public class Main2Activity extends Activity {
private EditText name;
private EditText pwd;
private CheckBox ck;
private Button bt;
private SharedPreferences sp;
private Editor edit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
//查找控件
name = (EditText) findViewById(R.id.name);
pwd = (EditText) findViewById(R.id.pwd);
ck = (CheckBox) findViewById(R.id.ck);
bt = (Button) findViewById(R.id.bt);
sp = getSharedPreferences("mysp", MODE_PRIVATE);
edit = sp.edit();
//判断 记住密码 是否被选中
boolean jizhumima = sp.getBoolean("jizhumima", false);
if(jizhumima){
ck.setChecked(true);
Intent intent = new Intent(Main2Activity.this,Main3Activity.class);
startActivity(intent);
}
//点击登录
bt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//记住密码被选中
if(ck.isChecked()){
edit.putBoolean("jizhumima", true);
}
edit.commit();
Intent intent = new Intent(Main2Activity.this,Main3Activity.class);
startActivity(intent);
}
});
}
}
第二次直接自动登录
最新推荐文章于 2021-11-04 16:03:01 发布