Hi all, I am using the following scope to launch t...
# coroutines
s
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
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
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
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