Reputation: 3462
I would turn the flags noHistory and excludeFromRecents, when the activity is already running. For example, when google chrome opens in incognito mode notification is generated, that when you click on it eliminates all activities of the stack and removed from recent. I want to do something like this, with some activities of my app.
Edit: The solution proposal by David Wasser works, but my problem is a bit more complicated. This is my manifest.xml
...
<activity
android:name=".ActivityRecive"
android:excludeFromRecents="true"
android:noHistory="true">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SEND_MULTIPLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
<data android:mimeType="video/*" />
</intent-filter>
</activity>
<activity
android:name=".ActivityPasswordToIncognito">
</activity>
<activity
android:name=".ActivityIncognitoMode1">
</activity>
<activity
android:name=".ActivityIncognitoMode2">
</activity>
<activity
android:name=".ActivityIncognitoMode3"
</activity>
...
ActivityRecive: begins as a result of intent. I want this activity is excluded from the stack and exclude From recent. ActivityRecive can launch ActivityPasswordToIncognito.
ActivityPasswordToIncognito: "normal" activity. ActivityPasswordToIncognito can launch ActivityIncognitoMode(X).
ActivityIncognitoMode(X): they can launch ActivityIncognitoMode(x+1) and I want that when the user exit from incognito mode are deleted from recent and stack.
The problem is that the root Activity(ActivityRecive) used android: excludeFromRecents="true", then the all activity in task is excluded from recent. I have tried using FLAG_ACTIVITY_NEW_TASK to launch ActivityPasswordToIncognito, but not work.
Upvotes: 0
Views: 1710
Reputation: 95636
If you want to make your entire application go away, and leave no trace in the "recent tasks" list, you should be able to do something like this:
Intent intent = new Intent(this, MyRootActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.putExtra("finish", true);
startActivity(intent);
In your root activity, add the following code to onCreate()
:
super.onCreate();
if (getIntent().hasExtra("finish")) {
// Need to finish now
finish();
return;
}
... rest of your onCreate() code...
This will clear the stack back to your root activity (the one with ACTION=MAIN and CATEGORY=LAUNCHER) and then the root activity will exit. Because the root activity is launched with Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
it shouldn't show up in the list of recent tasks.
NOTE: This will only work if your root activity stays in the activity stack when it launches other activities in your application (ie: doesn't call finish()
).
Upvotes: 1