开发者

call function from asynctask

开发者 https://www.devze.com 2023-02-28 17:59 出处:网络
Hello AsyncTask is not a member of activity. in separate class. how c开发者_Go百科an i call function of activity from AsyncTask ?

Hello AsyncTask is not a member of activity. in separate class. how c开发者_Go百科an i call function of activity from AsyncTask ? thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号