开发者

calling onDestroy in android shutdown

开发者 https://www.devze.com 2023-01-24 06:20 出处:网络
If I have a service running in my Android phone a开发者_高级运维nd I shutdown, will the service call onDestroy? I want the service to perform a task just before the phone shuts down. Although the Goog

If I have a service running in my Android phone a开发者_高级运维nd I shutdown, will the service call onDestroy? I want the service to perform a task just before the phone shuts down. Although the Google Droid guide says not to put such code in onDestroy, I do not know what else can be done.


If startService() is called to create your Service you should call stopService(), then onDestroy() will be called. If you use bindService() with BIND_AUTO_CREATE flag, than unbindService() caused onDestroy() automatically. What code they say shouldn't be put there? If it uses this Service of cause onDestroy() is not a good idea, if it's something like notification it's ok to put it there.

0

精彩评论

暂无评论...
验证码 换一张
取 消