Android:如何从首选项返回上一屏幕(按“后退”按钮)

发布于 2024-11-11 02:28:29 字数 403 浏览 6 评论 0原文

当从屏幕调用我的 PreferenceActivity 并按“后退”按钮后,返回屏幕始终是应用程序的主屏幕(应用程序启动后显示的活动)。是否可以返回到上一个屏幕?

我试图通过重写 onKeyDown (在我的 PreferenceActivity 类中)方法来解决这个问题,但没有运气:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

提前感谢您的帮助。

When calling my PreferenceActivity from a screen, and after pressing the Back button, the return screen is always the main screen (the activity that shows after app start) of the application. Is it possible to go back to the previous screen?

I tried to solve it through overriding the onKeyDown (inside my PreferenceActivity class) method without luck:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        finish();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

Thanks in advance for any help.

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

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

发布评论

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

评论(1

终止放荡 2024-11-18 02:28:29

假设您按照设计使用活动/意图,实际上不需要特殊代码。向后推将自动停止当前活动,并返回到调用它的活动。请参阅 Android 活动和任务指南

Assuming you use Activities/Intents as designed, there's actually no special code required. Pushing back will automatically stop the current activity, and go back to the activity which called it. See the Android Activity and Task guide.

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