https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
android
  • n

    Niraj Tiwari

    02/26/2021, 7:11 AM
    hi guys, I am trying to load a web view which plays video inside the loaded web page. I can see the video but the issue is that the full screen button is inactive. Anybody knows how to enable the full screen video playback inside a web view?
    :stackoverflow: 2
    g
    • 2
    • 1
  • c

    chrisxinyue

    02/26/2021, 8:42 AM
    Is
    onCommit{}
    builder being detached https://stackoverflow.com/questions/66382326/has-android-jetpack-compose-beta-detached-builder-of-oncommit ?
    g
    • 2
    • 8
  • t

    Travis Griggs

    02/26/2021, 8:51 PM
    I have a language/syntax question, I stumbled on it in Android... I was looking at some code that read:
    supportFragmentManager.commit {
    ...
    }
    When I see this pattern, I think "trailing closure syntax". On closer examination, I realized that
    this
    in said closure-esque body wasn't what I thought it was, so I went and found the method signature for FragmentManager.commit...
    FragmentManager.commit(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit
    I know that () -> Unit is a nullary closure, but what does it mean when I see the above? ClassName.() -> Unit?
    z
    • 2
    • 3
  • s

    Slackbot

    02/27/2021, 3:56 AM
    This message was deleted.
    👎 5
    k
    • 2
    • 1
  • k

    Kulwinder Singh

    02/28/2021, 7:34 AM
    Hi, Please anybody help me about this https://stackoverflow.com/q/66395913/6159314
    b
    • 2
    • 3
  • m

    melatonina

    02/28/2021, 7:28 PM
    Hello. Do you know any library of observable data structures that can be used on both JVM and Android?
    j
    • 2
    • 2
  • m

    Madalin Valceleanu

    03/01/2021, 8:13 AM
    📚 Sample Android Components Architecture on a Modular Word focused on the scalability, testability and maintainability written in Kotlin, following best practices using Jetpack. Application is based, apply and strictly complies with each of the following 5 points: • A 
    single-activity architecture
    , using the Navigation component to manage fragment operations. • Android 
    architecture components
    , part of Android Jetpack give to project a robust design, testable and maintainable. • Pattern 
    Model-View-ViewModel
     (MVVM) facilitating separation of development of the graphical user interface. •
    S.O.L.I.D
     design principles intended to make software designs more understandable, flexible and maintainable. •
    Modular app architecture
     allows being developed features in isolation, independently from other features. Project link: https://github.com/VMadalin/android-modular-architecture
    :kotlin-intensifies: 8
    👍 5
    :android-new: 3
    l
    • 2
    • 1
  • v

    Valtteri Puonti

    03/01/2021, 12:40 PM
    Apologies if wrong channel: how should I override
    activityResultRegistry
    in Activity tests? The docs have a clear example of testing Fragments, but that approach is not valid for Activities.
    i
    • 2
    • 1
  • c

    Chris Fillmore

    03/02/2021, 3:11 PM
    message has been deleted
    :kotlin-intensifies: 1
    c
    • 2
    • 18
  • t

    therealbluepandabear

    03/03/2021, 1:29 AM
    I am new to Android. What design pattern do you usually use with Kotlin apps? With Xamarin.Forms I used MVVM (which was great). What support is there for MVVM in native Android development? Are there any other design patterns that are used more commonly (such as MVC)?
    :google: 3
    a
    j
    • 3
    • 2
  • c

    Caio Costa

    03/03/2021, 2:44 AM
    Hey folks, how are you doing? I'd like to know if there's any advantage in using method references instead of Interface references when it comes to Listeners. Let's take for example the snippet of code below:
    // Using an Interface
    interface ABC {
        fun doIt()
    }
    
    private fun doIt() {
        val doItListener = object : ABC {
            override fun doIt() {
                println("Do it!")
            }
        }
        //Passing the Interface reference
        Main(doItListener)
    }
    
    // Class which the instruction will be executed in(Interface reference)
    class Main(listener: ABC) {
        init {
            listener.doIt()
        }
    }
    
    ----------------------------------------------------
    
    // Using Method reference
    private fun doIt2() {
        println("Do it!")
    }
    
    private fun callDoIt2() {
        //Passing Method reference
        Main(::doIt2)
    }
    
    // Class which the instruction will be executed in(Method reference)
    class Main(task: () -> Unit) {
        init {
            task()
        }
    }
    
    ----------------------------------------------------
    
    //Running
    fun main() {
        doIt()
        callDoIt2()
    }
    I ran both ways and both worked. But in my real scenario, the "Main" classes are Adapters and both doIt() and doIt2() would be instructions executed when users clicked an item of a list. Both examples would be triggered by such action individually. But my main question is: Does passing a reference of a method located at an Activity actually take with it any kind of information of such Activity which in this case is where it's located at? What do you think is the best approach in this case: A listener created from an Interface or putting all instructions inside a method and then passing its reference to an Adapter or whatever class it is. I'd like to hear from you guys. Thanks in advance.
    w
    • 2
    • 2
  • n

    Nraghuramireddy

    03/03/2021, 8:31 AM
    Hey Folks Need some suggestion on replacing Async tasks. We have very legacy code and Async tasks are being used heavily. Are there any alternatives to replace them such as Worker Manager or something else? Please suggest. FYI, We need a way to communicate back to Callie about the result.
    w
    • 2
    • 1
  • n

    note8g2018

    03/03/2021, 10:08 AM
    Please tell Google to update the code lab for jetpack compose https://developer.android.com/courses/pathways/compose It is not working now Because the code is old and there are many huge changes in the framework jetpack compose Google should update the code
    o
    e
    • 3
    • 2
  • i

    Issa

    03/03/2021, 10:14 AM
    Morning guys, We have an interesting use case of generics in kotlin:
    import kotlin.reflect.KClass
    
    fun main() {
        doSomething(B::class, C::class)
    }
    
    fun <T : A> doSomething(vararg dialogClasses: KClass<T>) {
        // no-op
    }
    
    open class A
    
    class B : A()
    
    class C : A()
    the compiler complains about the second argument of
    doSomething()
    function even if it is a sub-type of
    A
    . Is there any reason for this complaint? How can this issue can be solved?
    t
    a
    +2
    • 5
    • 5
  • j

    Johan

    03/03/2021, 10:31 AM
    Is there a deadline when Kotlin Synthetics is going to go from deprecated to removed? Or any official place it is being specifically stated?
    b
    • 2
    • 7
  • d

    Deepak Gahlot

    03/04/2021, 4:24 AM
    Hello, i have an query regarding registForActivityResult, when to get the URI for the file selected
    i
    e
    • 3
    • 20
  • a

    Anshulupadhyay03

    03/04/2021, 3:29 PM
    Hi everyone, I am working on a project where clean architecture is implemented. We have 3 modules app(android library), domain(java-library) , data(java-lib) . I am refactoring it to follow mvvm + livedata and retrofit in kotlin. Now domain and data being (java-lib), I can not use androidx libs (thats what i read). every sample codes i have gone through for mvvm+livedata+retrofit there is only one module i.e. app/presentation (android-lib). Can someone direct me to show how I can implement similar architecture having java modules in my project?
    a
    • 2
    • 2
  • s

    Sudhir Singh Khanger

    03/04/2021, 3:37 PM
    In the network layer of my app I have to save a bunch of values in shared preference. These values might be saved from several locations in the app. I am planning to put this task inside a WorkManager.
    ```    CoroutineScope(coroutineContext).launch {
            val saveProfileWork = OneTimeWorkRequestBuilder<SaveProfileWorker>()
                            .setInputData(
                                workDataOf(
                                    "IMAGE_URI" to "http://..."
                                )
                            )
                            .build()
            val request = WorkManager.getInstance(context).beginWith(saveProfileWork).enqueue().await()
            // post success
            return@launch
        }
    ``` 1. As far as my understanding goes launch starts a coroutine and await() awaits the result from another builder aynch(). This means I will be creating a coroutine inside a coroutine. Outer would be part of my network layer and inner one would be work manager's. I am not sure what should be done here. This also sounds like I might have issue handling exception. 2. How do I get success value from await call? If it asynchronous then return will end the outer launch coroutine.
    v
    • 2
    • 2
  • a

    allan.conda

    03/04/2021, 4:02 PM
    I’ve just read the new article about the recent Coroutines best practices on Android. Thank you so much for publishing these guidelines! I am happy to learn that I have been doing do a lot of these practices already and I’m sure the others are thankful too to have more guidelines regarding coroutines usage. I would just like to give my feedback (hopefully this Slack is a good place for it) in hopes of understanding these guidelines better for me and the others as well. I’ll take the chance to tag @Manuel Vivo hoping you can take time to read my thread 🙇. This just got me excited that I got up from my bed to ask and learn more about the article. My apologies if it’s too direct and you may ignore it. ⬇️
    t
    m
    • 3
    • 10
  • p

    pascalchidi

    03/04/2021, 9:56 PM
    I have a string “000016” When i call .toString() , it removes the zeros why ?
    d
    o
    • 3
    • 2
  • p

    pascalchidi

    03/04/2021, 9:57 PM
    the 000016 is a Long value. So when i call .toString on it, the zeros are gone. And it returns only 16.
    e
    c
    • 3
    • 2
  • a

    Anshulupadhyay03

    03/05/2021, 11:05 AM
    in flow from kotlin there is a method called stateIn to convert flow to stateFlow . signature of the method asks for Coroutine scope . what exactly i need to pass as scope ?
    d
    • 2
    • 3
  • m

    Martyna Maron

    03/05/2021, 4:25 PM
    Hiya 👋, I’m still trying to grasp coroutines and dispatchers, and I’ve encountered an issue in my Android app where the thread seemed to be blocked, which I’ve managed to fix but don’t quite understand why 😕 Any explanation would be appreciated! In
    onResume
    of my main fragment, I’ve got code like this (further down the chain, I don’t call this directly like this in
    onResume
    ):
    suspend fun onSessionStart() = withContext(Dispatcher.javascript) {
    
            for(feature in featuresList) {
                feature.setUpSynchronously()
    
                myActivity.lifecycleScope.launch(Dispatcher.javascript) {
                    feature.setUpAsync()
                }
            }
        }
    Right after I call this method above, I call this:
    suspend fun start() = withContext(Dispatcher.javascript) {
            //...
        }
    Note that
    setUpAsync()
    may call a method which switches to
    Dispatcher.network
    , but doesn’t launch a new coroutine. My problem is that on a fresh app launch, this code runs fine, but when I trigger
    onSessionStart
    again, when the app is still alive, I never get to
    start()
    and the app stalls. I can see by the logs that all of the
    setUpAsync()
    calls finish, but they don’t seem to return 🤷‍♀️🏻 Removing the context when launching the async set up, seems to fix the problem:
    myActivity.lifecycleScope.launch {
                    feature.setUpAsync()
                }
    But I don’t understand why, any idea?
    a
    a
    +3
    • 6
    • 9
  • j

    Jorge Andrés Díaz Naranjo

    03/05/2021, 4:29 PM
    Hi guys! A question: what solution do you recommend me to use
    Parcelable
    in a non-Android module? :bugdroid: I have modules with domain classes, but I need to pass them through bundle
    z
    a
    +2
    • 5
    • 12
  • g

    Gene Cahill

    03/05/2021, 4:43 PM
    I am working on a multi-platform project and in my commonTest it requires Robolectric test runner (i.e. @RunWith(Robolectric::class)) when running the android actual implementation. I’d like to get the benefit of having a single test execute for both android and ios targets without adding android dependencies to commonTest. Is there a clean way to do this?
    j
    • 2
    • 2
  • r

    Remy Benza

    03/05/2021, 5:30 PM
    is there a known issue with using a group inside MotionLayout to change visibility? Seems like it does not work
    j
    • 2
    • 12
  • p

    Patrick Yin

    03/06/2021, 12:24 AM
    Found 2 bugs in alpha version of AGP, but seems like I have no permission to report it. anyone knows that where we should report to?
    i
    • 2
    • 1
  • m

    melatonina

    03/07/2021, 6:07 PM
    Hello. I'm trying to share some ViewModels between the JavaFX version of my application, and the Android version. For this purpose, I'm replacing JavaFX
    ObservableProperty
    with `StateFlow`/`MutableStateFlow`. How can I perform the equivalent of the
    select
    operation with
    StateFlow
    ? The best that came to my mind is something similar to this function:
    fun <T, U> CoroutineScope.selectFlow(
        stateFlow: StateFlow<T>,
        op: (T) -> StateFlow<U>
    ): StateFlow<U> {
        // We can't create a MutableStateFlow without an initial value
        val mutableStateFlow = MutableStateFlow(op(stateFlow.value).value)
        var job: Job? = null
        launch {
            stateFlow.collect {
                job?.cancel()
                job = launch {
                    op(stateFlow.value).collect { 
                        mutableStateFlow.emit(it)
                    }
                }
            }
        }
        return mutableStateFlow
    }
    I don't know the StateFlow API very well. Is there a better way?
    m
    z
    • 3
    • 7
  • e

    Ezra En Yong

    03/08/2021, 3:36 AM
    Hey everyone! I wrote an article on the onboarding process for mobile development and how well both Apple and Android do in that aspect. While it's not strictly Android or Kotlin focused, it would be invaluable to hear about your experiences as new mobile developers and how well the article reflects on the onboarding process. Of course, constructive criticism of my writing is welcomed so please do reply to this message if you have anything to add.
    👍 2
    i
    • 2
    • 5
  • a

    Akinde Kolawole

    03/08/2021, 11:12 AM
    Hello, everyone. I tried using Hilt for Dependency injection, for the first time and, I have been having this error. java.lang.reflect.InvocationTargetExection(no error message)
    r
    • 2
    • 1
Powered by Linen
Title
a

Akinde Kolawole

03/08/2021, 11:12 AM
Hello, everyone. I tried using Hilt for Dependency injection, for the first time and, I have been having this error. java.lang.reflect.InvocationTargetExection(no error message)
r

Reprator

08/29/2021, 9:48 AM
Please read the full stacktrace
View count: 2