Share the post "Simulate Back Key Event Programmatically In Android"
This is how to simulate a back key press event in Android programmatically. Do note that this is called twice to dispatch a key event for both UP and down actions.
If only one of these two is executed, it will not work so make sure both of these are executed.
|
1 2 |
dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BACK)); dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BACK)); |