Nerethar Nerethar - 3 months ago 12x
Android Question

Android 5 - Activity gets send to background after onFinish

I want to destroy an Activity and call the

method to do so. In versions below Android 5.0.2 the Activity actually gets destroyed, but in Android versions above it wanders to the background instead of ending.
still gets called. Is there a flag I have to set or something for an activity to actually be destroyed no matter what an OS might want to say about that?


But my most notable observation is that the activity I want to be destroyed can be selected in the list of open tasks on devices

Sure. It's been that way for years. The recent-tasks lists (now referred to as the overview screen) shows recently-used tasks. This is not new to Android versions higher than 5.0.2. For example, the following screenshot shows the recent-tasks list from a Galaxy Nexus running Android 4.1.2:

Recent-Tasks List

I started up this device from a cold boot, launched the contacts ("People") app from the home screen, pressed BACK to exit and destroy that activity, then brought up the recent-tasks list and took the screenshot.

And that is not what I expect after calling finish() on an activity, when it is not a single activity application. One of my reasons to not expect that behavior is that on devices below Android 5.0.2 the said behaviour does not apply.

Then you have fallen through a rupture in the space-time continuum and wandered into a parallel universe, one where your unexpected behavior is how Android has been working for years and what ~1 billion people are used to. Also, in this parallel universe, I don't have hair, much to my chagrin.

There are ways to block your activity from showing up in the recent-tasks list (e.g., android:excludeFromRecents). However, that is not typical behavior.

How can I make sure that only one activity is shown in this list at any given time?

The list is of tasks, not activities. The only reason that your activity would appear multiple times in the list is if your activities are top-most on more than one task's BACK stack. You can take steps to try to manage this (e.g., android:taskAffinity) if the defaults are not working for you.