https://kotlinlang.org logo
#coroutines
Title
# coroutines
s

sjthn

08/10/2019, 5:38 PM
Hi all, I am using the following scope to launch the coroutine on button click. But the app crashes w/o any logs. Do you know what I am missing?
Copy code
private val scope = CoroutineScope(Dispatchers.Main + SupervisorJob())
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    presenter = ProductPresenter(ProductRepository(Network(), Database()), scope)

    button_fetch.setOnClickListener {
        presenter.onFetchClick()
    }
}

---------------------------------------------------------------------

    fun onFetchClick() {
        loadingState.value = true

        scope.launch {
            //...
        }
    }
l

louiscad

08/10/2019, 5:40 PM
You can try logging the error manually from a custom
Thread.UncaughtExceptionHandler
that you set in the
onCreate
method of your
Application
class (that you need to register in the manifest). I encountered such issues in the past where crash cause didn't show and that's how I worked around it until I saw double logs again.
s

sjthn

08/10/2019, 5:40 PM
When I use
GlobalScope
it's working fine
Looks like i didn't include
kotlinx-coroutines-android
dependency. That caused the uncaught exception 🙂 . A lint warning would have saved time. Thanks @louiscad
1
l

louiscad

08/10/2019, 9:11 PM
You can submit a feature request on kotl.in/issue so an inspection is added for android modules that have a dependency on kotlinx.coroutines-core but not on the android artifact.
s

sjthn

08/13/2019, 5:39 AM