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"
android:excludeFromRecents ensures the task is not listed in the recent apps. That is the reason, when android:excludeFromRecents is set to true for FromNotificationActivity , MainActivity disappers from history. Solution: Use android:taskAffinity to specify different tasks for both the activities.
You can use the manifest's <activity> tag to control which apps can start a particular activity. A parent activity cannot launch a child activity unless both activities have the same permissions in their manifest.
Try adding an unique taskAffinity:
<activity android:name=".OnInviteActivity"
android:label="@string/app_name"
android:taskAffinity=".OnInviteActivity"
android:excludeFromRecents="true"
android:noHistory="true"
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With