Reputation: 1490
I'm trying to finish an activity and not have it on the recents. The following code seems to work on KitKat but not on lolipop, as the activity always shows on the recents.
intentInvite = new Intent( context, OnInviteActivity.class );
intentInvite.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intentInvite.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intentInvite = createInviteIntent( intentCloud, intentInvite );
context.startActivity( intentInvite );
AndroidManifest.xml
<activity android:name=".OnInviteActivity"
android:label="@string/app_name"
android:excludeFromRecents="true"
android:noHistory="true"
Upvotes: 7
Views: 6660
Reputation: 4412
https://stackoverflow.com/a/27633500/1269737 - that's well known Android Issue.
This can be done programmatically
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); } }
If Task Root Activity is excluded from recent, all activities in this task will be excluded too.
Upvotes: 5
Reputation: 10120
I had the same issue with android Jelly Bean
and I had this in my manifest:
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:excludeFromRecents="true"
android:noHistory="true" />
I removed android:noHistory="true"
and it worked, the recent apps stopped showing my activity. Looks like the noHistory
and execludeFromRecents
are not compatible together for some reason.
Upvotes: 0
Reputation: 83028
This is a known issue into Android 5.0, since L preview. Seems Google is working on it.
Below are open issues for the same
Upvotes: 3
Reputation: 101
Try adding an unique taskAffinity:
<activity android:name=".OnInviteActivity"
android:label="@string/app_name"
android:taskAffinity=".OnInviteActivity"
android:excludeFromRecents="true"
android:noHistory="true"
Upvotes: 6