我在后台堆栈中有5个活动。我一次想从后台删除4个子活动。我怎样才能做到这一点?我不想手工完成每项活动。有什么方法可以让我的后台堆空吗?
答案 0 :(得分:3)
您可以使用FLAG_ACTIVITY_CLEAR_TOP
标记开始第五项活动。
答案 1 :(得分:0)
您想要的是基本上能够从与第一个不同的任何其他活动结束应用程序。
我所做的是使用一个应用程序变量来确定是否必须关闭应用程序,然后在onresume方法上检查它。
protected void onResume()
{
super.onResume();
if (!getMyApplication().isPlatformActive())
{
/* We finish every activity after resuming if we must shutdown application */
finish();
}
}
boolean isRootScreen()
{
/* Every activity will override this and set it to true if want to exit application from here */
return false;
}
protected void onBackPressed()
{
if(isRootScreen())
{
/* You could show a confirmation dialog here */
getMyApplication().setPlatformActive(false);
}
super.onBackPressed();
}