If you are trying to pass data into a new action, why not put it as a string in an intent? Then get this line from the intent in the new action. If you still need to save it, you can do it in the new onCreate () action after it pulls it out of intent.
Intent myIntent = new Intent(AddProblemActivity.this, ProblemActivity.class); //Add results here myIntent.putExtra("RecentProblemId", result); AddProblemActivity.this.startActivity(myIntent);
Then in onCreate of your new action do:
String recentProblemId = getIntent().getStringExtra("RecentProblemId");
Now, if you still need this information, follow these steps:
if(recentProblemId != null){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( ProblemActivity.this); prefs.putString("recent_problem_id",recentProblemId).commit(); }
I know this does not exactly answer your question about why String is not always bound to preferences in onPostExecute (). However, the best practice of transferring information between events is intentions and complementary services.
My guess about why this may not always work for some users is that their devices do not write data to the general settings file before starting a new action and try to read from the same file. Hope this helps.
source share