当用户点击子活动中的后退按钮时如何重新加载活动

发布于 2024-11-16 22:49:17 字数 547 浏览 1 评论 0原文

我有一个活动在 onCreate 方法中启动联系人选择器。当用户选择联系人时,该用户 ID 将传递到新的子活动。然而,如果用户按下后退键,他们会看到一个空白屏幕,因为 onCreate 似乎没有被再次调用。

我已经尝试过,onRestartonResume,它们解决了后面的问题,但是会发生什么情况,它会调用打开一个的竞争条件在将ID传递给子活动之前联系选择器活动。

编辑: 我正在使用 API 2.3.3。

我尝试在子活动中重载 onBack 方法来启动新活动。但是这样做会改变页面渲染的完成方式。当您启动新活动时,新活动从屏幕右侧进入,但是当您回击时,正常实现会导致前一个屏幕从左侧滑入。如果我重载 onBack 来调用新活动,则会发生用户按下后退按钮并且屏幕从屏幕右侧而不是左侧进入的情况。我需要让窗口滑动与默认模式相同。

I have an activity that launches the Contact picker in the onCreate method. When the user selects a contact, that user's ID gets passed to a new child activity. If the user presses the back key however, they get presented with a blank screen cause the onCreate doesn't seem to be getting called again.

I've tried, onRestart and onResume, which fix the back issue, but what happens it a race condition in which it will make the call to open up an Contact picker activity before the ID is passed to the child activity.

EDIT:
I'm using API 2.3.3.

I've tried the overloading the onBack method in the child activity to launch a new activity. But doing changes how the rendering of the page changes is done. When you launch a new activity the new activity comes in from the right hand side of the screen, but when you hit back the normal implementation causes the previous screen to slide in from the left-hand side. If I overload the onBack to call a new activity, what happens is the user hits the back button and a screen comes in from the right hand side of the screen as opposed to the left. I would need to have the window sliding be the same as the default pattern.

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

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

发布评论

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

评论(2

也只是曾经 2024-11-23 22:49:17

您无法在按下后退键时调用 onCreate。但是,您可以做一件事来完成联系人选择器活动。重写子活动中的 onBackPressed 函数并在那里启动一个新活动。

You cannot call onCreate on back key pressed. However you can do one thing that finish your contact picker activity. Override the function onBackPressed in Child activity and start a new Activity there.

吾性傲以野 2024-11-23 22:49:17
@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            moveTaskToBack(false);//this will not allow to go back

            //Here put your code i.e start new activity but first finish current activity

            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
@Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            moveTaskToBack(false);//this will not allow to go back

            //Here put your code i.e start new activity but first finish current activity

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