I have 3 activities A, B and C.
I inflate activity B dynamically on a button click and the user can add as many views as he likes.
The operation is like this:>
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch(keyCode) { case KeyEvent.KEYCODE_BACK: //bring back the previous activity do your logic here return false; } return super.onKeyDown(keyCode, event); }
You could use this, return false when activity should not be closed. use FLAG_ACTIVITY_REORDER_TO_FRONT to launch the previous activity