@SorryForMyEnglish's answer is right. You just cannot to implement it. By using android:noHistory="boolean"
attribute, see my concept maps below:
Because of ActivityC
and ActivityD
(last activities) has a true
value, so they cannot back to MainActivity
, but they can back to ActivityA
and ActivityB
. Also, ActivityA
and ActivityB
can back to MainActivity
. And the backstack is completely cleared without using this startActivity(intent)
to open your next Activity
(so you will need FLAG
):
Intent intent = new Intent(CurrentActivity.this, NextActivityToBeOpened.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
After you declared the value in manifest, you just need to call this startActivity(intent)
to open the next Activity
(no FLAG
is needed):
startActivity(new Intent(CurrentActivity.this, NextActivityToBeOpened.class));
Is it very simple, right?
Remember:
- Set your last
Activity
with android:noHistory="true"
in manifest.
- Another
Activity
must be set with false
value.
- Apply this attribute for all of your
Activity
.
As additional, here is how to use it inside your manifest:
<activity android:name=".MyActivity" android:noHistory="true" />
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…