Differences between Android killing an application and the user who disables it in the last list of applications

I am working on a project where, being at a specific event, we show a local sticky notification. It should also be when the application is minimized. What I have to do is to delete the local notification whenever the application is killed (from Android due to lack of memory or from the user, removing from the list of recent applications).

Normally, onDestroy will be called whenever Android performs an operation to open some space. This is normal in one of the cases, however, when using the application from the latest application lists, onDestroy is not called and a sticky notification remains.

What I did was I performed an empty service that will force onDestroy when the application is killed (both swipe and system wipe) so that I can delete my notification.

However, what I would like to do is the difference between hitting and deleting the system.

Is it possible?

+7
android android-activity android-lifecycle
source share
7 answers

In general, if Android wants to kill your application because it is too long (or because it wants to return resources), Android will simply kill the OS process that takes your application. It will not call finish() or onDestroy() for any Activity or Service components. The behavior of β€œswipe from the list of recent tasks” has changed over time and differs in different versions of Android. Someone should write a book about this: - (

+9
source share

This is the comment I found in reddit , which seems really interesting to me:

Scrolling an application will effectively kill most applications. You can verify this using ADB if you have the SDK installed. Swipe all the list of your reviewers, 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 main screen, it still works. Launch some other applications, and the com.google.android.browser process still exists.

Extract it from the address list and the process has disappeared. You can create a test application for further verification and make an onDestroy () call in your activity. It is not called when you are back or at home from the application, or when starting other applications. It is called when you are an app from the list of reviewers. I agree that the latest list apps are not really "multitasking."

The applications in the list do not necessarily start, processes can be killed by the memory manager long before you try to reopen it. However, you cannot argue that the only goal is to quickly switch to other applications when scrolling makes the actual process go away.

This is another good answer about what happens when you swipe an app from the list of recent apps. But the most interesting part was:

Actually, deleting a record in recent tasks will lead to the dismissal of any background of the processes existing for the process. It will not be directly services to stop, however there is an API for them to find out the task has been deleted, to decide whether they want it to mean that they should stop. It is so that the removal says that the recent task of the email application will not cause it to stop checking email.

If you really want to completely stop the application, you can long press the last tasks to go to the information about the application, and hit the force to stop there. To stop the complete destruction of the application - all processes are killed, all services are stopped, all notifications are deleted, all alarms are deleted, etc. The application is not allowed to run again until explicitly requested.

+1
source share

You can check when the user is silent about the application by adding a service to your application and implementing the onTaskRemoved method: fooobar.com/questions/99424 / ...

+1
source share

With Swiping, only the most recent tasks are removed from the recent task list. It was also called onDestroy before android 5.0. Perhaps you have a problem with level 20 api devices. System kill usually cannot be performed in the normal activity life cycle of Android. He just ends up at a back press event.

0
source share

when scrolling the application to the left, if any thread is still running in your application. Interruption, but the service is not stopped when you kill a convenient application. Thread and services stop.

0
source share

the behavior is similar, but not exactly the same as closing the application - in the general case (for applications that do not define explicit reverse control of buttons) it is the same as a good enough time from the application that you go out to check this discussion of links , he has a good contribution to the topic

0
source share

First, let's find out one thing: Android MAY NOT CALL onDestroy() . Referring to the Activity Page , from Honeycomb on, onPause() and onStop() guaranteed to be called before the application is killed.

Keep in mind that this semantics will change slightly between platform-oriented applications, starting with HONEYCOMB and from targeting to previous platforms. Starting with Honeycomb, the application is not in a killable state until its onStop () returns. This affects when onSaveInstanceState (Bundle) can be called (it can be safely called after onPause () and allows the application to wait safely while onStop () maintains a constant state.

So, after (hopefully) clearing the ether from the Android life cycle, I think that you can achieve what you want by adding the delete code from onStop() instead. If you need it because the user is really returning to a specific Actvitiy (IE is not killed), you can return it to onRestart() .

0
source share

All Articles