Skip Manifest Attribute Activity
It depends on the need, but if we just want to just skip the activity in the return flow, then it is useful to remove this activity from the history in the manifest.
[1] β [2] β [3] - normal flow
[1] <- [3] - reverse flow
Then for [2] . We can set the noHistory attribute in the Manifest attribute:
<activity android:name=".SecondActivity" android:noHistory="true" />
Thanks to this approach, our [2] activity will never be launched in the return flow.
Use intent flag
Removing activity from the history stack is not always a good idea, for example, if our activity sometimes requires a reverse flow, and sometimes not, then to start the drawing we need to set a flag with the intention:
Intent intent = new Intent(this, FirstActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(intent);
And itβs very important - in the FirstActivity manifest to set the launch mode to singleTop .
<activity android:name=".FirstActivity" android:launchMode="singleTop" />
Without activating the activity, the launchMode attribute will be restored.
source share