Skip to content Skip to sidebar Skip to footer

Differentiate Between Android Killing The App And User Swiping It Off On The Recent Apps List

I am working on a project, where while being on a specific Activity we show a local sticky notification. That should also be the case when the app is minimized. What I have to acco

Solution 1:

In general, if Android wants to kill your application because it has been in the background for too long (or because it wants to reclaim resources), Android will just simply kill the OS process hosting your app. It will not call finish() or onDestroy() on any Activity or Service components. The behaviour of "swipe from recent tasks list" has changed over time and is different in different Android versions. Someone should write a book about that :-(

Solution 2:

You can check for when the user swipe-closes the app by adding a service to your app, and implementing the onTaskRemoved method: https://stackoverflow.com/a/26882533/2441655

Solution 3:

This is a comment I found in reddit that seems to me really interesting:

Swiping an app away will effectively "kill" most apps. You can test this out using ADB if you have the SDK installed. Swipe everything out of your recents list, then launch the browser.

Use ADB to run 'ps' on the device and verify that the com.google.android.browser process is running. Go to the home screen, it's still running. Launch some other apps, and the com.google.android.browser process is still there.

Swipe it out of the recents list, however, and the process is gone. You can create a test app to further verify, and log the onDestroy() call in your Activity. It's not called when you back or home out of the app, or when you launch other apps. It does get called when you swipe the app out of the recents list though. I do agree that the recent apps list isn't really "multitasking".

The apps in the list aren't necessarily even running, the processes could have been killed by the memory manager long before you try to re-open it. However, you can't argue that the only purpose is to jump quickly to other apps when the swiping makes the actual process go away.

This is another good answer about what happen when you swipe an app out of the recent apps list. But the part that I liked most was:

Actually, removing an entry in recent tasks will kill any background processes that exist for the process. It won't directly causes services to stop, however there is an API for them to find out the task was removed to decide if they want this to mean they should stop. This is so that removing say the recent task of an e-mail app won't cause it to stop checking for e-mail.

If you really want to completely stop an app, you can long press on recent tasks to go to app info, and hit force stop there. For stop is a complete kill of the app -- all processes are killed, all services stopped, all notifications removed, all alarms removed, etc. The app is not allowed to launch again until explicitly requested.

Solution 4:

By Swiping from recent task list removes only from recent tasks .. It was also called onDestroy before android 5.0 . Might be you are having issue above api level 20 devices. System kill normally can not be executed in normal android activity lifecycle. It just finishes the activity on back press event.

Solution 5:

when swiping app to left if any Thread still run in your app Interrupted but service not stopped, when you kill handy app Thread and services are stopped.

Post a Comment for "Differentiate Between Android Killing The App And User Swiping It Off On The Recent Apps List"