getLifecycle().getCurrentState()
给了我错误的状态。
我尝试使用下面的代码。 我搜索了谷歌,但没有人对此感到奇怪。 我缺少什么吗?
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.i(MainActivity::class.java.name, "onCreate : " + lifecycle.currentState.name)
}
override fun onStart() {
super.onStart()
Log.i(MainActivity::class.java.name, "onStart : " + lifecycle.currentState.name)
}
override fun onResume() {
super.onResume()
Log.i(MainActivity::class.java.name, "onResume : " + lifecycle.currentState.name)
}
override fun onPause() {
super.onPause()
Log.i(MainActivity::class.java.name, "onPause : " + lifecycle.currentState.name)
}
override fun onStop() {
super.onStop()
Log.i(MainActivity::class.java.name, "onStop : " + lifecycle.currentState.name)
}
override fun onDestroy() {
super.onDestroy()
Log.i(MainActivity::class.java.name, "onDestroy : " + lifecycle.currentState.name)
}
}
答案 0 :(得分:0)
如果您查看文档,则您的实际行为是预期的行为: https://developer.android.com/topic/libraries/architecture/lifecycle
将状态视为图的节点,将事件视为这些节点之间的边缘。