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

发布于 2024-11-29 22:12:53 字数 232 浏览 0 评论 0原文

我有一个具有以下活动的应用程序;

登录->首页区->交互记录器(触摸屏来记录交互)

虽然此交互记录器处于活动状态,但我希望能够允许用户通过后退键或主页键退出应用程序,并且仍然能够返回到该交互记录器。但是,如果交互记录器完成(在计时器上管理),则用户将进入登录活动

另外,我是否应该在交互记录器中覆盖后退键,因为我不希望用户在记录期间破坏活动

预先感谢,

安迪

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柒夜笙歌凉 2024-12-06 22:12:53

您需要禁用设备的所有按键并需要处理返回键。重写以下方法,但请记住,您无法控制 home 键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;
}

在从一个 Activity 移动到另一个 Activity 时,要实现应用程序退出要求,请完成如果您需要回来,请返回上一篇并开始...

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文