Carl K.
Carl K.

Reputation: 457

Android: How to return to previous screen from Preferences (pressing Back button)

When calling my PreferenceActivity from a screen, and after pressing the Back button, the return screen is always the main screen (the activity that shows after app start) of the application. Is it possible to go back to the previous screen?

I tried to solve it through overriding the onKeyDown (inside my PreferenceActivity class) method without luck:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

Thanks in advance for any help.

Upvotes: 1

Views: 3130

Answers (1)

PearsonArtPhoto
PearsonArtPhoto

Reputation: 39698

Assuming you use Activities/Intents as designed, there's actually no special code required. Pushing back will automatically stop the current activity, and go back to the activity which called it. See the Android Activity and Task guide.

Upvotes: 2

Related Questions