I have an app that binds a service which saves data to the phone's file manager at various times during the application's life cycle (the app is in the background while it's doing this). If something happens to invalidate the data, the data should be discarded once the service completes. (Note that it does do so successfully as long as the service's life cycle is uninterrupted). However, if I swipe away the app while the service is running, the data is not discarded.
The issue is that the activity's onDestroy()
method is never called, while onStop()
has already occurred because the app is in the background.
Furthermore, the service's onTaskRemoved()
is never called (possibly because it's a bound service? Yes, I put android:stopWithTask="false"
in the service's declaration in the manifest), nor is onUnbind()
or onTrimMemory()
when the app is swiped away. The service and app just kind of end.
How can I know that the service/app is being killed in order to discard data before that happens?