简体   繁体   English

Android - 活动堆栈,将当前活动置于前面并禁用返回键

[英]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 taken 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 ..覆盖以下方法,但请记住您无法控制home keyend 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...为了在从一个活动移动到另一个活动时满足您的应用退出要求,完成前一个活动并在需要返回时启动它......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM