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.
Expecting a service to be force closed seems kinda weird to me. Anyways if the process is terminated i would expect any open file handle to be closed by the linux subsystem.
Also as stated by CommonsWare onDestroy isn't guaranteed in any case.
It's worse. onDestroy is only called in emulator environment (for testing), but never on a real phone....
And exactly as @mibollmba said - files will be closed when process dies. No need to handle file close.
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.