I have 8 Activities in my Android app and I want:
1)Every time I press Back button during my first 7 Activities to go back to my previous Activity(Act1< Act2< Act3< Act4< Act5< Act6< Act7) BUT
2)ONLY when I am in the 8th Activity I want to definitely exit my Android app and go to my phone's Home Screen.I try to do it by overriding onBackPressed method
in my 8th Activity (Phone Home Screen<-Act8)
I found an Android implementation in which I insert finish();
in every intent of all my 8 Activities but this is not what I want since this way I can't go back to the previous Activity whenever I want(with finish();
every current Activity is removed from back stack).
How will I do it please?
My code so far in my 8th Activity is:
@Override
public void onBackPressed()
{
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}