Monday, January 7, 2013

Detect (And Cancel) Android Back Key

To detect when the user presses the back key, you just have to override the onBackPressed function.

Just like this:
@Override
public void onBackPressed() {
    super.onBackPressed();
}
You can optionally cancel the navigation or allow it to occur.

You cancel the navigation by not calling the instruction on like two.

Obviously you can code any logic to conditionally cancel the navigation.

Another use is to catch the event just to persist any information and then letting the navigation occur.

No comments:

Post a Comment