使用SharedPreferences进行存储状态

user=getSharedPreferences("user", Context.MODE_PRIVATE);
boolean isBoolean = user.getBoolean("isBoolean", false);

     //第一次进入是false
      //在第二次进入时得到的是Editor存放为true的布尔值所以判断成立 直接跳转


 if (isBoolean){
    Intent intent=new Intent(Welcome.this,MainActivity.class);
    startActivity(intent);
    finish();
}else{
    SharedPreferences.Editor edit = user.edit();
    edit.putBoolean("isBoolean",true);
    edit.commit();
}

你可能感兴趣的:(使用SharedPreferences进行存储状态)