当我在onDestroy方法中调用stopSelf时会发生什么?

huangapple go评论63阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月26日 15:38:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76554510.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定