Amna Mirza Amna Mirza - 15 days ago 7
Android Question

Android how to close a running app on back press?

How to exit from an app on back press of main activity?
I am using this code, but its finish main activity and show other activities from back stack.

@Override
public void onBackPressed() {
finish();
}

Answer

I tried this and its work for me really well,as I am working on app, where once session get expired, user is able to see only few views and remain hidden.

    @Override
    public void onBackPressed() {
        moveTaskToBack(true);
    }
Comments