Android - Activity stacks, bringing current activity to front and disabling back key
I have an application which has the following activities;
Login -> Home Area -> Interaction recorder (touch screen to record interaction)
Whilst this interaction recorder is active i want to be able to allow the user to exit the app through either the back key or home key and still be able to get back to that interaction recorder. However if the interaction recorder is finished (managed on a timer) then the user is tak开发者_开发技巧en to the login activity
Also, should I override the back key whilst in the interaction recorder because I do not wish for the user to destroy the activity during its recording
thanks in advance,
Andy
you need to disable all the keys of device and need to handle back key. Override the below method but remember you can not control the behaviour of home key
and end call key
..
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(KeyEvent.KEYCODE_MENU == event.getKeyCode() || KeyEvent.KEYCODE_DPAD_LEFT==event.getKeyCode()
|| KeyEvent.KEYCODE_DPAD_DOWN==event.getKeyCode() || KeyEvent.KEYCODE_DPAD_RIGHT==event.getKeyCode()
|| KeyEvent.KEYCODE_DPAD_UP==event.getKeyCode() || KeyEvent.KEYCODE_DPAD_CENTER==event.getKeyCode())
{
return false;
}else if(KeyEvent.KEYCODE_BACK==event.getKeyCode()){
//Do your task here...
}
return true;
}
to achieve your app exit requirement while moving from one activity to another finish the previous one and start it if you need to come back ...
精彩评论