从asynchTask呼叫runonuithread [英] Call runonuithread from asynchTask

查看:275
本文介绍了从asynchTask呼叫runonuithread的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点难倒一个问题,原谅我,因为我很新的Andr​​oid开发。我做了一些搜索,发现不少不同意见。我有一个调用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆