android activity back stack
I have 5 activity in back stack. At a time, I want to remove 4 child activity from back stack. how can I do this? i dont want to finish each activity by hand. is there any method wh开发者_JAVA百科ich can make my back stack empty?
You can start your fifth activity with the FLAG_ACTIVITY_CLEAR_TOP
flag.
What you want is essentially being able to end application from any other activity different from the first one.
What I do is using an application variable determining if application must be shutdown and then check it on the onresume method.
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();
}
精彩评论