Android:如何从首选项返回上一屏幕(按“后退”按钮)
当从屏幕调用我的 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您按照设计使用活动/意图,实际上不需要特殊代码。向后推将自动停止当前活动,并返回到调用它的活动。请参阅 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.