开发者

Android - Activity stacks, bringing current activity to front and disabling back key

开发者 https://www.devze.com 2023-03-28 12:24 出处:网络
I have an application which has the following activities; Login -> Home Area -> Interaction recorder (touch screen to record interaction)

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 ...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号