SharedPreferences用法
判断第一次进入
SharedPreferences name = getSharedPreferences("name", 0);
boolean key = name.getBoolean("key", true);
if (key) {
// 第一次登陆时的流程
SharedPreferences.Editor edit = name.edit();
edit.putBoolean("key", false);
edit.commit();
startActivity(new Intent(MainActivity.this, Main2Activity.class));
finish();
} else {
// 第二次登陆的流程
startActivity(new Intent(MainActivity.this, Main3Activity.class));
finish();
}
存取值
SharedPreferences sharedPreferences = getSharedPreferences("", MODE_PRIVATE);
SharedPreferences.Editor edit = sharedPreferences.edit();
edit.putString("123", "ddfjh");
edit.commit();
String qqqqq = sharedPreferences.getString("123", "qqqqq");
网友评论