允许在 onPause() 之前或期间显示对话框吗?
我为 Android 创建了一个简单的游戏;我想防止用户因意外按下主页或后退按钮而将游戏发送到后台。我计划使用对话框来确认用户的操作。如果您需要插图,我想要的与 Sirius 在他们的应用程序中所做的类似。
我尝试将此操作添加到重写的 onPause() 中,但该活动在显示对话框后立即消失,所以我认为我没有以正确的方式处理此问题。我该如何解决这个问题?
任何帮助表示赞赏。
I have created a simple game for Android; I want to prevent users from sending the game to the background by pressing the home or back buttons accidentally. I planned on using a dialog to confirm the user's action. What I want is similar to what Sirius does with their app, if you need an illustration.
I tried adding this action to an overridden onPause(), but the activity vanishes right after the dialog is displayed, so I don't think I'm going about this the right way. How can I fix this?
Any help is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只能覆盖后退按钮。您无法覆盖主页按钮。这或多或少是出于安全原因(以防止某人的手机被劫持)。
请参阅这两个问题。
You can only override the back button. You cannot override the home button. This is more or less for security reasons (to prevent someone's phone from getting hi-jacked).
See these two questions.