问题摘要
getLifecycle().getCurrentState()
给了我错误的状态。
环境(集成库、操作系统等)
- compileSdkVersion:27
- targetSdkVersion : 27
- 支持库:27.1.1
预期行为
- onCreate() -> 已创建
- onStart() -> 开始
- onResume() -> 恢复
- onPause() -> 开始
- onStop() -> 已创建
- onDestroy() -> 销毁
实际行为
- onCreate :初始化
- onStart :已创建
- onResume :开始
- onPause : 开始
- onStop : 已创建
- onDestroy : 销毁
问题详情
我尝试使用下面的代码。我搜索了谷歌,但没有人对此感到奇怪。我是不是少了点什么?
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)
}
}