Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove app from recent apps programmatically

Tags:

android

I know that Activities can be declared in manifest as being excluded from recents with android:excludeFromRecents: http://developer.android.com/guide/topics/manifest/activity-element.html#exclude

However, that's not what I'm looking for, I would like to know if there is a way to remove the app from recent apps programmatically

like image 358
pandre Avatar asked Nov 14 '12 18:11

pandre


People also ask

How do I delete an app from my recent apps?

Large thumbnails of recently used apps display with each app's icon. To remove an app from the list, hold your finger down on the thumbnail for the app you want to remove until a popup menu displays. Touch “Remove from list” on that menu. NOTE: Notice the “App info” option available on the popup menu.


2 Answers

Yes, generally when you want to have special properties for an Activity when starting it you supply special flags to the Intent. In this case FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS.

Updated:

If you need to hide the current already running activity, you might be able to use this flag in combination with FLAG_ACTIVITY_CLEAR_TOP which would send the new Intent to the existing Activity. You'll have to think and perhaps experiment with what happens as the user moves around your stack though and whether that will make your app re-appear in the recent apps.

like image 182
kabuko Avatar answered Sep 20 '22 14:09

kabuko


This can be done using the ActivityManager.AppTask functionality (starting in API 21)

    ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);     if(am != null) {         List<ActivityManager.AppTask> tasks = am.getAppTasks();         if (tasks != null && tasks.size() > 0) {             tasks.get(0).setExcludeFromRecents(true);         }     } 
like image 25
user3276567 Avatar answered Sep 16 '22 14:09

user3276567