2

I want to clear the back stack within an Activity but not by startActivity() and using FLAG. e.g. when I launch an application from the application icon then the application main activity starts but there is some thing in the back stack like the launcher activity because when we touch the minimized app tab the launcher is visible . I want to remove the launcher application from the minimized applications.

SoftRock
  • 96
  • 11

2 Answers2

3

@SorryForMyEnglish's answer is right. You just cannot to implement it. By using android:noHistory="boolean" attribute, see my concept maps below:

concept

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" />
Anggrayudi H
  • 14,977
  • 11
  • 54
  • 87
1

use android:noHistory="true" attribute in Manifest for your Activity

<activity android:name="StartActivity"
            android:noHistory="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
SorryForMyEnglish
  • 1,181
  • 7
  • 14
  • this did not worked when I launch my application the launcher is in the minimized application ( back stack ) – SoftRock Jan 05 '15 at 15:29