从asynchTask呼叫runonuithread [英] Call runonuithread from asynchTask
问题描述
我有点难倒一个问题,原谅我,因为我很新的Android开发。我做了一些搜索,发现不少不同意见。我有一个调用Web服务并返回一堆JSON结果的AsynchTask。我有(安培;想)异步运行我的web服务。结果集将需要一个RelativeLayout的内内联呈现。我试图做到这一点在我的异步线程而Android不允许从更新的任何UI不是主线程。
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.
我看到了Runonuithread,但我无法从我的UI线程中调用我的asynchtask。
I see the Runonuithread but I can't call my asynchtask from my ui thread.
什么是异步调用我的web服务,得到的结果,然后将原来的线程上更新mainUI的最佳途径。是否有一个最佳实践架构的角度来看。
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.
推荐答案
onPostExecute()是在UI线程上运行,因此尝试使用该方法做你的工作。否则,你可以使用Handler类线程之间进行通信。
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.
这篇关于从asynchTask呼叫runonuithread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!