I have a TabActivity that shows other Activities as content based on the selected tab. What I want to do is try to capture the back key from the "parent" action, but onKeyDown () nor onBackPressed () is ever called in the parent ... it is handled by the "child" actions. Is there a way to translate it into "parent" activity?
Why not just use the Activity child from within:
@Override public void onBackPressed () { this.getParent().onBackPressed(); }
TabActivity .
Handler TabActivity, onCreate TabActivity.
getHandler() ( TabActivity).
:
@Override public void onBackPressed () { MyTabActivity.getHandler().sendEmptyMessage(MyTabActivity.BACK_PRESSED); }
I ran into the same problem. I tricked him like this:
@Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) { //things u want to do when back key pressed } return super.dispatchKeyEvent(event); }