Situations when a Service's onDestroy() method doesn't get called?

会有一股神秘感。 提交于 2019-11-29 07:46:44

I'm aware that a Service's onDestroy() method may never be called but can someone tell me when such a scenario might occur?

Here are three off the top of my head:

  • If the user Force Stops you from the Settings app

  • If Android needs RAM in a hurry (e.g., to process an incoming phone call) and elects to terminate your process to free up that RAM

  • You terminate the process from DDMS

Also, if your service crashes with an unhandled exception somewhere, Android may consider the service to be defunct and skip onDestroy(). I'm not sure about this one, as I haven't specifically tried it.

But I'm wondering if it's possible for a service to "go away" without onDestroy() being called, while the observers it created would live on and continue to receive changes.

Other than the unhandled-exception possibility I mention above, I am reasonably certain that if the process will be terminated in the conditions where onDestroy() is not called.

Also if the app is reinstalled/updated , ondestroy() is never called.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!