AsyncTask onPostExecute crashes (reports nullpointerexecption) when I try to use the value I received from doInBackground to update SharedPreferences.
My handle to the calling activity is: private DashboardActivity<?> callerActivity;
with out the <?>
it complains. I've trie a couple of ways: 1) update SP in onPostExecute as:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(callerActivity);
prefs.edit().putInt("lastrecord", intRec ).commit();
I've also called a method in the callerActivity as:
callerActivity.storeLastInsertedRecord(intRec);
All the errors are the same, nullpointerexection on these lines.
What might I be doing wrong? This answer Android - shared preferences set in an AsyncTask onPostExecute() not always set? by @denisdrew is the closest, but for it crashes at the same place when I try instantiate the intent:
Intent myIntent = new Intent(callerActivity.getApplicationContext(), SharedPrefsHelperActivity.class);
or
Intent myIntent = new Intent(callerActivity.getBaseContext(), SharedPrefsHelperActivity.class);
what might I be doing wrong? I know that the value that I'm trying to push is not null (intRec).