其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