1.创建SharedPreferences对象:
SharedPreferences dataBase = getSharedPreferences("SharedPreferences", Activity.MODE_PRIVATE);
SharedPreferences.Editor edit = dataBase.edit();
2.保存数据:
dataBase.edit().putString("NAME", userName.getText().toString()) ;
dataBase.edit().putString("PASS", password.getText().toString())
dataBase.edit().commit();
3.读取数据:
String name = dataBase.getString("NAME", "");
String pass = dataBase.getString("PASS", "");
Toast.makeText(this, "读取数据如下:"+"\n"+"name:" + name + "\n" + "pass:" + pass,Toast.LENGTH_LONG).show();
4.删除数据:
dataBase.edit.remove("name").commit();
dataBase.edit().clear().commit();