0

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!

Paradox
  • 4,602
  • 12
  • 44
  • 88

1 Answers1

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:

link

link

Community
  • 1
  • 1
A. Binzxxxxxx
  • 2,812
  • 1
  • 21
  • 33