Force closing application with service: onDestroy () is not called in the service?

I have implemented a sticky service, and when I forcefully close the application, I see that Activity onDestroy () is being called. But the service, apparently, does nothing.


here is 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 () does not call: stopService (), finalize () or onDestroy ()! I put Log calls in all 3 of them.

how to know when the service is closed? I need to capture this event so that I can close the files.

+7
source share
3 answers

how to know when the service is closed?

Not. onDestroy() cannot be called on any component.

I need to capture this event so that I can close the files.

Then do not leave them open.

+9
source

Expecting that the service is closed by force, it seems strange to me. In any case, if the process is completed, I expect that any open file descriptor will be closed by the linux subsystem.

Also, as stated in CommonsWare onDestroy, in any case is not guaranteed.

0
source

This is worse. onDestroy is called only in the emulator environment (for testing), but never on a real phone ....

And just like @mibollmba said, the files will be closed when the process freezes. No need to process the file.

-one
source

All Articles