I have an application that involves navigation. If the user starts a navigation, a kind of "navigationLifecycleManager" is created. This is stored in the application instance so that it survives configuration changes, switching between acitivities etc..
However if the user "quits" the application, I want to kill some background threads, store some minor data into the application storage and so on. So i need some hook(s) that tell me when the app quits.
Must of this can be achieved by overriding "onPause" and checking "isFinishing". But this doesn't solve the swiping out of the recent apps list. The swiping doesn't seem to call anything. Neither "onPause", "onDestroy" nor "onTerminate" is called in the activity/application.
You can't handle swipe, because system just removes your process from memory without calling any callback. I have checked, that before user calls "recent apps" screen, onPause() will be always called. So you need to save all data in onPause method without checking isFinishing().
When Android decides to kill our app, our activities will call onDestroy method. But before that, one more method will be also called and that is onSaveInstanceState(Bundle). If we check the first method, which is called when opening new activity, onCreate(Bundle), we can see the Bundle parameter.
for User kill( use App switcher ): counter activity number/taskstack etc. (unspecify)for Android Framework kill(Low Memory etc): (unspecify)for Native kill(Process. kill kill signal): use native.
The simplest way to keep background apps in check is using Android's Adaptive Battery feature. Turn it on by going to Settings > Battery > Adaptive preferences and toggle Adaptive Battery on. Update your device!
You can't handle swipe, because system just removes your process from memory without calling any callback.
I have checked, that before user calls "recent apps" screen, onPause()
will be always called. So you need to save all data in onPause
method without checking isFinishing()
.
To check back button, use onBackPressed method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With