问题1:能不能在GlobalScope.launch(Dispatchers.Main){} 做耗时事情
问题2: delay() 算不算耗时的
案例1:
findViewById<View>(R.id.btn1).setOnClickListener {
GlobalScope.launch(Dispatchers.Main){
Thread.sleep(21000)
Toast.makeText(this@MainActivity,"sdfs",Toast.LENGTH_SHORT).show()
}
}
效果:直接ANR了
案例2:
findViewById<View>(R.id.btn1).setOnClickListener {
GlobalScope.launch(Dispatchers.Main){
delay(20000)
Toast.makeText(this@MainActivity,"sdfs",Toast.LENGTH_SHORT).show()
}
}
效果:20秒以后显示了 Toast