Call runonuithread from asynchTask

被刻印的时光 ゝ 提交于 2019-12-08 10:08:59

问题


I am a bit stumped on a problem and forgive me as I am very new to android development. I did some searching and found quite a few differing opinions. I have an AsynchTask that calls a webservice and returns a bunch of json results. I have to (& want to) run my webservice asynchronously. the result set will need to be rendered inline within a RelativeLayout. I attempted to do this in my asynchronous thread but Android doesn't allow updating the UI from anything that isn't the main thread.

I see the Runonuithread but I can't call my asynchtask from my ui thread.

What is the best way to call my webservice asynchronously, get the results, and then update the mainUI on the original thread. Is there a best practices from an architecture perspective.


回答1:


onPostExecute() is run on the ui thread, so try using that method to do your work. Otherwise, you can use the Handler class to communicate between threads.



来源:https://stackoverflow.com/questions/13348979/call-runonuithread-from-asynchtask

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!