跟进https://stackoverflow.com/a/3448189,实际显示密码屏幕的最佳方法是什么?
我的第一次尝试是使用LockActivity启动subactivity:
// MainActivity.javapublic voID onResume() { super.onResume(); ApplicationState state = ((ApplicationState) getApplication()); if ((new Date().getTime() - state.mLastPause) > 5000) { // Prompt for password if more than 5 seconds since last pause Intent intent = new Intent(this, LockActivity.class); startActivityForResult(intent, UNLOCKED); }}
但是,如果LockActivity显示的时间超过5秒,这将导致MainActivity在解锁后再次暂停.
因此,我有一些想法:
>使用片段显示MainActivity内部的主屏幕或锁定屏幕.
>将对话框显示为锁定屏幕(不是首选).
>使用多个if … else分支检查是否已设置密码,并且MainActivity暂停的时间超过5秒.
举个例子,我想实现与DropBox应用相同的行为(使用“密码锁定”选项).
处理此问题的正确方法是什么?
附言我不确定是否应该将此问题作为原始问题发布,从而挖掘出旧的思路.我觉得发布一个新问题是更清洁的解决方案.
解决方法:
由于我是一个问另一个问题的人,所以我不妨告诉您我是如何解决的.我正在使用一个对话框提示输入密码(我确实知道您不喜欢该密码,但是它可能会对其他人有所帮助),并确保取消密码的唯一方法是输入正确的密码.
MyApplication app = ((MyApplication)getApplication());if (new Date().getTime() - app.mLastPause > 5000) { // If more than 5 seconds since last pause, check if password is set and prompt if necessary SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); String password = pref.getString("password", ""); if (password.length() > 0) { // Prompt for password MyPasswordDialog dlg = new MyPasswordDialog(this, password); dlg.setownerActivity(this); dlg.show(); }}
在MyPasswordDialog的OnCreate()方法中,我确保它不可取消
protected voID onCreate(Bundle savedInstanceState) { this.setCancelable(false); // ...and some other initializations}
总结 以上是内存溢出为你收集整理的跟进密码保护启动Android应用程序全部内容,希望文章能够帮你解决跟进密码保护启动Android应用程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)