我希望能立即启动一个协程。我有一段代码:
class SampleActivity : AppCompatActivity(), CoroutineScope {
private var job: Job = Job()
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + job
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.d("SampleActivity", "Before launch")
launch {
Log.d("SampleActivity", "Inside coroutine")
}
Log.d("SampleActivity", "After launch")
}
}
输出结果如下:
Before launch
After launch
Inside coroutine
有可能按照以下顺序输出吗?
Before launch
Inside coroutine
After launch