Android实例-手机安全卫士(十三)-根据实际情况合理弹出对话框

一、目标

  根据用户是否已经设置防盗密码弹出不同的对话框。若已经设置防盗密码,则弹出输入密码对话框;若未设置防盗密码,则弹出设置密码对话框。

二、代码实现。

  1、在主界面代码中新建方法(showSecurityDialog),用于判断是否已经设置防盗密码,并弹出相应的对话框。

    ①.通过SharedPreferences对象(sp)的getString(String key, String defValue)方法获取config文件中password对应String类型的值。

    ②.通过TextUtils的isEmpty(CharSequence str)方法判断是否为空。如果非空,则调用显示输入密码对话框(showinputPwdDialog())方法;如果为空,则调用显示设置密码对话框(showSetPwdDialog())方法。

新建方法(showSecurityDialog)代码如下:

1 protected void showSecurityDialog() {        
2         // 判断config文件中保存着的密码
3         String savedpassword = sp.getString("password", null);        
4         if(!TextUtils.isEmpty(savedpassword)){
5             showinputPwdDialog();
6         }else{
7             showSetPwdDialog();
8         }                
9     }
View Code

 

  2、在主界面代码的onCreate方法中的case 0:(进入“手机防盗”界面)里面调用新建的方法。 

 

posted @ 2015-01-26 13:22  红烧大白鲨  阅读(152)  评论(0编辑  收藏  举报