其onStart()中的Activity
綁定到MusicPlayService
,並且在其onStop()中取消綁定MusicPlayService
。在它的onDestroy()調用的stopService,但的MusicPlayService
的的onDestroy()是沒有得到所謂的可言。未綁定並停止服務的onDestroy未調用
****** UPDATE:它是()的isFinishing在的onDestroy是假的。如果按下返回按鈕,activity :: onDestroy()就有isFinishing == true,並且如果按home按鈕調用onDestroy()(我有'不保持活動活着'設置選中),但isFinishing ==假。
我想這是正確的行爲,只有活動的結束()將開始設置isFinishing ==真。即使home按鈕會觸發onDestroy(),os仍然可能認爲這不是真正的「完成」。
想知道新牌坊生命週期LifecycleRegistryOwner可能提供了一些掛鉤的活動是真正被摧毀。
下面是活動的片段:
override fun onStart() {
super.onStart()
if (!isBound) {
val bindIntent = Intent(this, MusicPlayService::class.java)
isBound = bindService(bindIntent, myConnection,
Context.BIND_AUTO_CREATE)
}
}
override fun onStop() {
super.onStop()
unbindService(myConnection)
isBound = false
}
override fun onDestroy() {
super.onDestroy()
if (isFinishing) {
val intentStopService = Intent(this, MusicPlayService::class.java)
stopService(intentStopService)
}
}
發現它是isFinishing導致該問題的檢查,但爲什麼當的onDestroy的isFinishing還是假的? – lannyf