英文:
What happens when i call stopSelf in onDestroy method?
问题
override fun onDestroy() {
Timber.d("$this: onDestroy")
stopSelf()
super.onDestroy()
}
英文:
I have such a method implementation and I want to understand what will happen when this method is called. Could you give me a hint
override fun onDestroy() {
Timber.d("$this: onDestroy")
stopSelf()
super.onDestroy()
}
答案1
得分: 0
onDestroy()
只应在Android已停止Service
时调用。如果Service
正在运行,Android不会调用onDestroy()
。如果在onDestroy()
中调用stopSelf()
,它应该什么都不做,因为Service
已经停止。
英文:
onDestroy()
should only be called by Android when the Service
has already stopped. Android won't call onDestroy()
if the Service
is running. If you call stopSelf()
in onDestroy()
it should just do nothing, as the Service
is already stopped.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论