Somewhere in your AsyncTask
you'll want to pass in your activity. Then you'll save that reference in a weak reference. Then you can dereference and use it again in onPostExecute
.
Class member:
WeakReference<Activity> weakActivity;
Somewhere in AsyncTask
, probably either constructor or onPreExecute
:
weakActivity = new WeakReference<Activity>(activity);
In onPostExecute
:
Activity activity = weakActivity.get();
if (activity != null) {
// do your stuff with activity here
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…