3

I know how to remove an application or activity from recent list by adding android:excludeFromRecents="true" to Manifest file. This will remove the activities when they are not in the foreground.

I tried adding the flag FLAG_ACTIVITY_CLEAR_TOP also. But, no activities on the foreground can be hidden from recent list when the home button is long pressed during that time. My activity gets killed when swiped away from the recent list, while it is in the foreground. How to remove the foreground activity or a whole foreground application from Recent list?

Manoj Perumarath
  • 6,251
  • 4
  • 39
  • 57
Ameena Shafeer
  • 566
  • 2
  • 14
  • Are you saying if an app is in foreground and you hit recent apps you don't want it to appear in the recents? – sanjeev Nov 20 '19 at 05:47
  • @sanjeev exactly.. – Ameena Shafeer Nov 20 '19 at 05:48
  • Does this answer your question? [Remove app from recent apps programmatically](https://stackoverflow.com/questions/13385289/remove-app-from-recent-apps-programmatically) – Manoj Perumarath Nov 20 '19 at 05:54
  • @ManojPerumarath Nop..Bcoz, it says abt removing it through code. What I want is to hide foreground activity from recents by any means. – Ameena Shafeer Nov 20 '19 at 05:59
  • 1
    @ManojPerumarath I ve gone through all those solutions, but nthng work to hide a foreground app – Ameena Shafeer Nov 20 '19 at 06:29
  • I am testing on Samsung A10 (API 28) , in my project, minSdkVersion 21 and targetSdkVersion 29. – Ameena Shafeer Nov 20 '19 at 06:47
  • this is in my manifest declaration. And, intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); is also called while starting the activity. – Ameena Shafeer Nov 20 '19 at 06:50
  • 1
    @AmeenaShafeer As I checked it, adding `android:excludeFromRecents="true"` to your launcher activity in manifest removes the whole app from recent app's list even when the app is running, in Android 7.0 only. In Android 8.0 and above, I think OS doesn't allow the app / activity to be removed from recent / running apps' list. minSdkVersion: 23 targetSdkVersion: 28 – Mudassir Nov 20 '19 at 12:11

1 Answers1

1

You cannot "hide" your application from the user this way. Tasks with running activities are always displayed in the list of recent tasks.

The only way to remove your task from the list of recent tasks is to set android:noHistory="true" on all <activity> declarations in the manifest. However, this will cause the activities to be finished when the user navigates away from them (ie: presses the HOME button or the "recents" button, so this is probably not what you want.

David Wasser
  • 85,616
  • 15
  • 182
  • 239