android 本地存储数据

 String PREFS_NAME = "lmn.com";
 String ItemUser = "username";
 String ItemPass = "password";
 String ItemCheck = "check";

 

一 存储

   SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
    SharedPreferences.Editor editor = settings.edit();
    editor.putBoolean(ItemCheck, checkBox.isChecked());
    editor.putString(ItemUser, username);
    editor.putString(ItemPass, password);
    editor.commit();

二 读取

 SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
  boolean silent = settings.getBoolean(ItemCheck, false);
  String username = settings.getString(ItemUser, "");
  String password = settings.getString(ItemPass, "");

你可能感兴趣的:(android,String,存储)