mornindew
mornindew

Reputation: 2221

Pass Variables from AsyncTask back to calling to Activity

I am new to Android Development and have a question (will probably show my newbie status). I am calling an asynchtask from a custom activity. Once the asynch task is completed onPostExecute I would like to call back into my activity and set a pojo (Map()). I know that onPostExecute seems to run on the UI thread but I am not sure how to get visibility into the calling Activity.

The goal is to be able to have some variables set in my activity and ideally the webservice call will already be completed.

Thanks, Craig

Upvotes: 0

Views: 801

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93569

If the AsyncTask is a subclass of the activity, it has access to all public, protected, and private variables of the superclass. If its not, you need to write a public function in the Activity class to set the variables, and call it from the AsyncTask. That will probably require you to pass the activity to the AsyncTask via the constructor and save it in a member variable of the task.

Upvotes: 2

Related Questions