Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove singleTask activity with taskAffinity from recent tasks when it is finished?

Let assume we have two activities.

A - main activity, that is "home launcher enabled" (proper intent filters etc.)

B - task root activity with singleTask specification (there can be only one instance of this activity) and with custom taskAffinity (to differentiate if from the main task root).

Let assume that B represents a task, that is valid only when it is not finished - returning to it or starting it again from recent tasks after finishing it is not an option.

In some point of the time - A starts B to begin a new task. The goal is to remove B from recent task list when user finishes B. User may navigate from B to other tasks (using home long press) and then navigate back to B as long as it is not finished. Launching A from launcher won't bring B to the foreground as they have different task affinities.

Android recognizes B as a root of a task, thus B is visible in the recent tasks list even if it is finished, and user can always go back to it. It is not a solution to move B to the one task with A, because in the time B is running - user should be able to switch between A and B tasks. Adding excludeFromRecents to B's manifest removes it completely from recent tasks list, and it is bad solution too.

How to achieve it? (sorry for my bad english)

like image 881
Michael P Avatar asked Jun 06 '12 19:06

Michael P


1 Answers

Standard Answer

Sorry to be the bearer of bad news, but this functionality cannot be achieved utilizing standard methods without overriding the way that your app works. Even then, it will only work for as long as your app is running. Furthermore, doing so will require a rooted device with a specialize ROM because you cannot override the functionality of the Home button in anyway. All you can do is respond to onNewIntent() which does not fire if you are long pressing the Home button.

Recent Tasks is specifically for ease of use to the user to allow them to get back to whatever apps they have been using, regardless of whether the app is running. There is good news, however. This process is not keeping your app alive! It is simply an icon pointing to your package.

Unfortunately, this means that if your app is still running, something else is going on that is keeping it running.

Non-Standard Answer

It may be possible by editing the package properties during run-time (much in the same way that you can enable/disable components from java code). This is highly discouraged, because Recent Tasks is a usability feature of the Android core platform. This would require some research.

like image 107
Fuzzical Logic Avatar answered Nov 15 '22 21:11

Fuzzical Logic