17

I'm launching an activity from a service and want it to appear in the recent apps list.

However, I want the activity to be removed from the recent apps list if I exit the application (e.g. press button on activity's UI which calls finish()).

Excluding the activity from the recent apps list with android:excludeFromRecents="true" does not give me the initial activity behaviour that I require, i.e. the activity appearing in the recent apps list.

Is this possible?

PJL
  • 18,735
  • 17
  • 71
  • 68

3 Answers3

17

Use

android:excludeFromRecents="true"

for the activity in manifest file

android:excludeFromRecents

Whether or not the task initiated by this activity should be excluded from the list of recently used applications ("recent apps"). That is, when this activity is the root activity of a new task, this attribute determines whether the task should not appear in the list of recent apps. Set "true" if the task should be excluded from the list; set "false" if it should be included. The default value is "false".

Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • 3
    Require the initial state of the activity to be in the recent apps list. – PJL Feb 19 '14 at 09:26
  • 1
    if initial state of the app is not in the recent apps then it's not working. How to solve this problem please help – Ajit Kumar Dubey Aug 03 '15 at 14:25
  • @ajit no idea sorry!. In fact i might have misread the question and answered. – Raghunandan Aug 03 '15 at 14:28
  • @Raghu, I am trying to find this solution from last 5 Days even I have post question regarding this but didn't get any solution – Ajit Kumar Dubey Aug 03 '15 at 14:32
  • @ajit i don't think its possible. Atleast not that i know off. – Raghunandan Aug 03 '15 at 14:33
  • http://stackoverflow.com/questions/31693570/application-should-not-display-in-recent-app-list-after-finish-the-new-activity?noredirect=1#comment51330227_31693570 this is link if you find any gold point it will more helpful for me – Ajit Kumar Dubey Aug 03 '15 at 14:33
  • @Raghunandan see the question I hope you can give some other ideas, Problem is that when app is not in background incoming call come after disconnect call it should not be in recent apps – Ajit Kumar Dubey Aug 03 '15 at 14:37
  • @ajit whats app could be using a foreground service also. I am not sure. But i do not know any other solution. – Raghunandan Aug 05 '15 at 13:35
9

for api > 21 you can try finishAndRemoveTask() instead of finish()

Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78
0

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.

source

Community
  • 1
  • 1
Viswanath Lekshmanan
  • 9,945
  • 1
  • 40
  • 64