SERG
SERG

Reputation: 3971

call function from asynctask

Hello AsyncTask is not a member of activity. in separate class. how can i call function of activity from AsyncTask ? thanks

Upvotes: 0

Views: 1955

Answers (1)

Vladimir Ivanov
Vladimir Ivanov

Reputation: 43108

You can pass an instance of your activity in the constructor of your AsyncTask. But be sure to call the methods of activity only inside onPreExecute() and onPostExecute() methods, becuase they run on the UI Thread.

If you want to call some activity code while doInBackground(), then you should create a Handler and pass it to the AsyncTask, because you can not modify the ui from non UI thread.

Upvotes: 1

Related Questions