我想通过sharepreferance将字符串存储在内存中,但是有一些问题无法存储在内存中,请告诉我如何解决这个问题?需要任何许可吗?
代码::
SavePreferences("MEM1", LanguageSelcted);
LoadPreferences();
方法::
public void SavePreferences(String key, String value) {
try {
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(key, value.trim());
editor.commit();
} catch (Exception e) {
e.printStackTrace();
}
private void LoadPreferences() {
try {
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
LanguageSelection = sharedPreferences.getString("MEM1", "");
Log.i(TAG, "LanguageSelection is :>>>" + LanguageSelection);
Toast.makeText(getBaseContext(), "LanguageSelection is :>>>" + LanguageSelection, Toast.LENGTH_LONG).show();
/*
* textSavedMem1.setText(strSavedMem1);
* textSavedMem2.setText(strSavedMem2);
*/
} catch (Exception e) {
e.printStackTrace();
}
}