小编Pro*_*igy的帖子

在协程范围内调用时启动不执行

我在协程范围内调用 launch 但它不执行。Snackbar 操作监听器正在执行,但启动块由于某种原因没有执行。

CoroutineScope(Dispatchers.Main).launch {
    val scope = this
    val mn = snackbarManager(R.id.root)
    Snackbar
        .make(mn.container, R.string.recpt_deleted, Snackbar.LENGTH_LONG)
        .setAction(R.string.undo) {
            scope.launch { // not executing
                Toast.makeText(requireContext(),"Committing",Toast.LENGTH_LONG).show()
                Log.d("COMMIT", "calling commit")
            }
        }
        .show()
}
Run Code Online (Sandbox Code Playgroud)

android kotlin android-snackbar kotlin-coroutines coroutinescope

9
推荐指数
1
解决办法
5908
查看次数