我是用来判断在app运行过程中不用多次判断是不是输入了密码
不知道是否影响app的运行效率
package com.anew.note.utils;
import android.content.Context;
/**
* Created by pig on 2016/12/2.
*/
public class JudgeUtils {
private JudgeUtils() {
}
//用单例模式来判断,static公用,final太监类,不能被重写,
private static JudgeUtils judgeUtils;
public static JudgeUtils getIntence(Context context){
if (judgeUtils==null){
judgeUtils = new JudgeUtils();
}
return judgeUtils;
}
private boolean isPass =false;
public boolean isPass() {
return isPass;
}
public void setPass(boolean pass) {
isPass = pass;
}
}
activity中的应用
//设置
1. if (a.equals(SPUtils.getInstance(getApplicationContext())
.getStringValue(“note”)) ) {
Intent intent = new Intent(CheckActivity.this, ScrollingActivity.class);
startActivity(intent);
//通过以后就不需要输入密码
JudgeUtils.getIntence(getApplicationContext()).setPass(true);
finish();
}
if (!a.equals(SPUtils.getInstance(getApplicationContext())
.getStringValue(“note”))) {
Toast.makeText(getApplicationContext(),”密码错误,请重新输入”,Toast.LENGTH_SHORT).show();
}
//获取
1. if (JudgeUtils.getIntence(getApplicationContext()).isPass()){
Intent intent = new Intent(getApplicationContext(), ScrollingActivity.class);
startActivity(intent);
finish();
}
else {
Intent intent = new Intent(getApplicationContext(), CheckActivity.class);
startActivity(intent);
finish();
}