存
// data 指定的文件名 SharedPreferences.Editor editor = getSharedPreferences("data",MODE_PRIVATE).edit(); editor.putString("name","liu"); editor.putInt("age", 112); editor.commit();
取
SharedPreferences preferences = getSharedPreferences("data",MODE_PRIVATE); String name = preferences.getString("name","");//getString第二个单位空串意思是取不到name的默认值,getint同理可证
int age = preferences.getInt("age",0);
System.out.println(name+" "+ age);