Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top