我的 Android 应用程序的密码对话框
我的主要活动是密码对话框(@android:style/Theme.Dialog)。身份验证成功后,它会启动应用程序页面(也是一个 Activity),并自行调用 finish()。对我来说重要的是密码对话框独立启动而不是浮动在应用程序页面的顶部。
第一次一切都很好。但是,当用户按“主页”离开应用程序,然后单击“桌面”上的应用程序图标返回时,密码对话框不会再次启动(因为调用了 onResume)。如果用户按“后退”按钮离开应用程序,然后重新启动应用程序,则会调用密码对话框。
我越想这个,我的解决方案就变得越不优雅!我希望这里有一个简单的解决方案。当我写这篇文章时,我尝试了在密码对话框上不调用 finish() 的选项,但这并没有改变任何事情。
My MAIN Activity is a password dialog (@android:style/Theme.Dialog). Upon successful authentication, it launches the application page (also an Activity), and calls finish() on itself. Its important to me that the password dialog launch standalone and not float on top of the application page.
Everything is fine the first time. However when the user leaves the app by pressing Home, and then returns back by clicking the app icon on the "desktop", the password dialog does not launch again (since onResume is called). If the user presses the Back button to leave the application, and then relaunches the app, the password dialog is called.
The more I think about this, the less elegant my solutions are becoming! I hope there is a simple solution here. As I write this, I tried the option of not calling finish() on the password dialog, but that didn't change a thing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的 onResume() 方法中(当从按下“主页”按钮恢复时),再次调用登录。很抱歉回答这么短,但这听起来是最合理的解决方案:)。
In your onResume() method (when resuming from say a "home" button press), make a call to login again. Sorry for such a short answer, but that sounds like the most reasonable solution :).
最后,我决定在 onResume() 中使用计时器。如果上次请求密码是在 30 秒前,那么我会再次显示该对话框。是的,我正在使用模糊(谢谢杰克!)。
Finally, I decided to use a timer in onResume(). If the last time a password has been requested is over 30 seconds ago, then I show the dialog again. And yes I am using blurring (thanks Jack!).