我想使用參數存儲一些設置,使用了這段代碼:
SharedPreferences pref = getPreferences(MODE_WORLD_WRITEABLE);
pref.edit().putString("some settings", "lalal");
pref.edit().commit();
文件已經創建了,但是內容為什麼是空的呢?
SharedPreferences customSharedPreference = getSharedPreferences("myCustomSharedPrefs", Activity.MODE_PRIVATE);
SharedPreferences.Editor editor = customSharedPreference.edit();
editor.putString("some settings", "lalal");
editor.commit();
然後再用這段代碼獲取值:
SharedPreferences shf = getSharedPreferences("myCustomSharedPrefs", MODE_WORLD_READABLE);
String strShPref = shf.getString("some settings", "");