我实现了一个棘手的服务,当我强行关闭应用程序,我看到活动的的onDestroy()被调用。但该服务不显然做任何事情。
这里的logcat的:
07-01 22:35:30.397:DEBUG / ActivityMine(6505)的onDestroy()07-01 22:35:32.667:信息/ ActivityManager(71):强制停止包my.large.package的uid = 1003607-01 22:35:32.667:在5000毫秒坠毁服务my.large.package调度重启/ .service.ServiceCommunicator:WARN / ActivityManager(71)07-01 22:35:32.667:信息/流程(71):发送信号。 PID:6505 SIG:907-01 22:35:32.687:信息/ ActivityManager(71):强制停止服务ServiceRecord {451f65b8 my.large.package / .service.ServiceCommunicator}
你可以看到,ServiceCommunicator()不会调用:stopService(),完成(),或的onDestroy()!我已经把登录在他们所有的3个电话。
我怎么知道什么时候该服务被强制关闭?我需要捕获该事件,因此我可以关闭文件。
解决方案我怎么知道什么时候该服务被强制关闭?
您没有。 的onDestroy()
不能保证被调用,任何组件。
我需要捕获该事件,因此我可以关闭文件。
那就不要让他们打开。
I've implemented a sticky service and when I force close the app I see that the Activity's onDestroy() is called. But the service doesn't apparently do anything.
here's the logcat:
07-01 22:35:30.397: DEBUG/ActivityMine(6505): onDestroy()
07-01 22:35:32.667: INFO/ActivityManager(71): Force stopping package my.large.package uid=10036
07-01 22:35:32.667: WARN/ActivityManager(71): Scheduling restart of crashed service my.large.package/.service.ServiceCommunicator in 5000ms
07-01 22:35:32.667: INFO/Process(71): Sending signal. PID: 6505 SIG: 9
07-01 22:35:32.687: INFO/ActivityManager(71): Force stopping service ServiceRecord{451f65b8 my.large.package/.service.ServiceCommunicator}
as you can see, ServiceCommunicator() doesn't call: stopService(), finalize(), or onDestroy() ! I've put Log calls in all 3 of them.
how do I know when the service is force closed? I need to trap that event so that I can close files.
解决方案how do I know when the service is force closed?
You don't. onDestroy()
is not guaranteed to be called, on any component.
I need to trap that event so that I can close files.
Then don't leave them open.
相关推荐
最新文章