Issue
I've tried following methods for detecting back press in an activity:
private static final String TAG = "PRESSED";
@Override
public void onBackPressed() {
Log.i(TAG,"BACK");
super.onBackPressed();
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.i(TAG, "Back pressed");
}
return super.onKeyUp(keyCode, event);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.i(TAG, "Back pressed 1");
}
return super.onKeyDown(keyCode, event);
}
UPDATE:
The onKeyDown, onKeyUp and onBackPressed WORK on pressing back button on "On screen buttons" at bottom of screen, which is this:

But DO NOT WORK WHEN pressing the Up button in title bar, which is this:

Why don't they work when Up button in title bar is pressed?
Solution
Maybe this? It makes ActionBar back button work like the back button.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
Answered By - Andrea Dusza
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.