Your onPostExecute()
is wrong. NEVER create an instance of the activity yourself, let alone via the constructor. Instead, your AsynTaskRequest
needs to have some means of communicating back to its activity. It also needs to deal with the fact that the activity may change while this work is going on, due to the user rotating the screen or some other configuration change.
You could:
Use an event bus (
LocalBroadcastManager
, Otto, greenrobot's EventBus, etc.), and haveonPostExecute()
raise an event that the activity picks up when the work is done, orMove the
AsyncTask
to be an inner class of a retained fragment, so the task works with the fragment inonPostExecute()
, and the fragment knows the right activity to talk to, or
Other patterns exist, but those are two to start with.