Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove application from recent application list?

Tags:

android

I guess that Android won't let people to do this, because they think they have perfect handle for the task/applications. However, I really need to do this in my case.

I have an activity A acting as the entry point of my application. In that activity, it reads the preference and decided which activity to start, say B or C. After that, it finishes itself. So, activity A never appears to the users.

My application stores things on sdcard, and reads from it constantly. So, when the sdcard is unmounted, I need to display a message to the user that the sdcard is unavailable, instead of opening B or C. I set a check in A to display that message when sdcard is unavilable. When that message is displayed, A will not try to start B or C.

Things works perfectly if user only enter my application from application launcher. However, I found that user can also enter my application by long pressing home and choose it from the recent application list, if he has opened it recently. When user does that, it skips A and goes directly to B or C. I don't have the check in both of them, so exception is thrown while I am trying to access sdcard, and force close dialog pops up.

I can simply move my check to both B and C to fix this problem. But in the future, the number of activities started from A will increase. If there are 6 of them, I'll need to copy this check to 6 places. Needless to say, this looks very ugly, and is a maintenance nightmare.

So, the best fix should be removing my application from recent application list when the sdcard is uunmounted. However, I can't find how to do this. Even killing the process or use ActivityManager.restartPackage, it still appears in the list. Can anyone tell me how to remove it from the list?

like image 574
user412759 Avatar asked Sep 21 '10 17:09

user412759


People also ask

Can you please remove all the recent apps?

So when you want to clear all the recently used apps, double press the home key, and then close all. Swipe down, settings, Advanced, double press home key, select the option for recent apps. So when you want to clear all the recently used apps, double press the home key, and then close all.


1 Answers

try

<activity android:name=".MainActivity"         android:excludeFromRecents="true" ... 

in your AndroidManifest.xml's activity declaration.

like image 123
whlk Avatar answered Sep 24 '22 11:09

whlk