In my application I'm using Shared Preferences to save my app settings.
here is the way I define a Shared Prefrences:
sharedPreferences = context.getSharedPreferences(getString(R.string.last_update_key),MODE_PRIVATE);
String shared = sharedPreferences.getString(getString(R.string.last_update_key),"0");
and my ASyncTask onPostExecute block that uses passed Shared Preferences:
protected void onPostExecute(String result) {
if(result == "true"){
textView.setText(R.string.updated_message);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(context.getString(R.string.last_update_key),getCurrentTimeStamp());
try {
editor.putString("s_app_name",json3.getJSONObject(0).getString("value"));
editor.putString("s_township_name",json3.getJSONObject(1).getString("value"));
editor.putString("s_welcome_message",json3.getJSONObject(2).getString("value"));
}catch (JSONException e){
}
editor.commit();
}
but the strings that I put them in try block will not display in my activity and I do not get any error in catch. here is how I get my saved value :
SharedPreferences sharedPref = context.getSharedPreferences(
getString(R.string.last_update_key), Context.MODE_PRIVATE);
String welcome_message = sharedPref.getString("s_welcome_message","");
the problem is that I can get the value of R.string.last_update_key
but not the others.