简体   繁体   中英

Android app stack is not clearing

in my android app i wrote a below code to clear the stack of the activities, but this code is not working, so i request you to provide me working snippets on this.

Intent intent = new Intent(UserProfile.this, Login.class)
        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
finish();
startActivity(intent);

Thanking you

In API level 11 a new Intent Flag was added : Intent.FLAG_ACTIVITY_CLEAR_TASK Try this flag. Example :

Intent intent = new Intent(UserProfile.this, Login.class)
        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
finish();
startActivity(intent);

You can use ActivityName.this.finish().

 Intent intent = new Intent(UserProfile.this, Login.class)
        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
  YourActivityName.this.finish();

If current Activity is A and you wants to launch B Activity, also, C and D paused in background, FLAG_ACTIVITY_CLEAR_TOP will finish C and D but not A.

there is a workaround can let you finish A activity. Create a "static" Handler that can do finish() while receive message in A activity, then sendMessage using static Handler from A while B activity started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM