讀取資料範例
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String fileName = "save_file";
SharedPreferences sharedPreferences = getSharedPreferences(fileName, Context.MODE_MULTI_PROCESS);
String valueOne = sharedPreferences.getString("KeyNameOne", "Nothing");
int valueTwo = sharedPreferences.getInt("KeyNameTwo", 0);
float valueThree = sharedPreferences.getFloat("KeyNameThree", 0.0F);
long valueFour = sharedPreferences.getLong("KeyNameFour", 0L);
boolean vlaueFive = sharedPreferences.getBoolean("KeyNameFive", false);
String result = valueOne + "\n" +
valueTwo + "\n" +
valueThree + "\n" +
valueFour + "\n" +
vlaueFive + "\n";
TextView v = new TextView(this);
v.setText(result);
setContentView(v);
}
}