判断账户,记住密码,自动登录,传值

判断账户

if (a) {

    if (b) {
        //显示进度条,视图层
        mProgressDialog.show();
        //1.使用presenter,这个处理业务逻辑的类,对用户输入信息是否正确进行判断
        mUserLoginPresenter.login(user);
    } else {

        mProgressDialog.show();
        mUserLoginPresenter.shiyiya();
    }

} else {
    //视图层
    Toast.makeText(MainActivity.this, "输入不能为null", Toast.LENGTH_SHORT).show();
}

P层

//对用户手机号进行判断,业务逻辑
public boolean shiyi(User user){
    if(user.number.length() != 11){
        return false;
    }
    return true;
}

public void shiyiya(){
    //2.开一个子线程做耗时操作,业务逻辑
    new Thread() {
        public void run() {
            mUserLoginPresenterInterface.panduan();
        }
    }.start();
}

记住密码,自动登录

sharedPreferences = getSharedPreferences("denglu",MODE_PRIVATE);
//记住密码
boolean isCheckJZ = sharedPreferences.getBoolean("isCheckJZ", false);
String numberb = sharedPreferences.getString("numberb", "");
String passwordb = sharedPreferences.getString("passwordb", "");
if (isCheckJZ) {
    number.setText(numberb);
    password.setText(passwordb);
    ck_jizhu.setChecked(true);
}
//自动登录
boolean isCheckDL = sharedPreferences.getBoolean("isCheckDL", false);
if (isCheckDL) {
    startActivity(new Intent(MainActivity.this,Main2Activity.class));
    finish();
}

if (ck_jizhu.isChecked()) {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("numberb", numbera);
    editor.putString("passwordb", passworda);
    editor.putBoolean("isCheckJZ", true);
    editor.commit();
}else{
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putString("numberb", numbera);
    editor.putString("passwordb", passworda);
    editor.putBoolean("isCheckJZ", false);
    editor.commit();
}

if (ck_zidong.isChecked()) {
    SharedPreferences.Editor editor = sharedPreferences.edit();
    editor.putBoolean("isCheckDL", true);
    editor.commit();
}

传值

Intent intent = new Intent(MainActivity.this, SecondActivity.class);
                intent.putExtra("namea",list.get(position).getName());
                startActivity(intent);
                finish();

//获取传递过来的数据
        tv3 = findViewById(R.id.tv3);
        String namea = getIntent().getStringExtra("namea");
        tv3.setText(namea);

猜你喜欢

转载自blog.csdn.net/weixin_42270281/article/details/83961052