I am creating an android app with Eclipse and currently when I press back until the stack is empty(using NavUtils.navigateUpFromSameTask(this)), it exits the application. However, I was wondering how I could check if the stack is empty or not so that when it is empty, I could go to the main menu instead of exiting the application. Help is greatly appreciated!
Asked
Active
Viewed 102 times
1 Answers
0
i think you are looking for this:
@Override
public void onBackPressed() {
if(getIntent().hasCategory(Intent.CATEGORY_LAUNCHER)) {
//this is the last activity on stack
doSomethingSpecial();
} else {
super.onBackPressed();
}
}
maybe also interesting:

Community
- 1
- 1

A. Binzxxxxxx
- 2,812
- 1
- 21
- 33