简体   繁体   English

Android应用程序堆栈未清除

[英]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. 在我的Android应用程序中,我编写了下面的代码来清除活动堆栈,但是此代码无法正常工作,因此我要求您为此提供工作摘要。

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. 在API级别11中,添加了新的Intent标志: Intent.FLAG_ACTIVITY_CLEAR_TASK尝试使用此标志。 Example : 范例:

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

You can use ActivityName.this.finish(). 您可以使用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. 如果当前活动为A,并且您想启动B活动,并且C和D在后台暂停,则FLAG_ACTIVITY_CLEAR_TOP将完成C和D而不是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. 创建一个可以在A活动中接收消息的同时执行finish()的“静态”处理程序,然后在B活动启动时使用A的静态处理程序sendMessage。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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