我在后台堆栈中有5个活动。一次,我想从后台堆栈中删除4个子活动。我该怎么做呢?我不想手工完成每一项活动。有什么方法可以让我的后台堆栈清空吗?
发布于 2011-07-29 14:49:38
您可以使用FLAG_ACTIVITY_CLEAR_TOP
标志开始您的第五个活动。
发布于 2011-07-29 15:00:11
你想要的本质上是能够从任何不同于第一个活动的其他活动中结束应用程序。
我所做的是使用一个应用程序变量来确定应用程序是否必须关闭,然后在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();
}
https://stackoverflow.com/questions/6869556
复制相似问题