安卓:调用从AsyncTask的doInBackground方法UI线程的方法 [英] Android : Calling the methods on UI thread from AsyncTask doInBackground method

查看:120
本文介绍了安卓:调用从AsyncTask的doInBackground方法UI线程的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的AsyncTask将数据上传到用户界面。我写的code,从服务器在一个单独的方法下载的数据和我打电话从doinBackground该方法。它会给错误,因为用户界面的方法不能从doInBackground.but访问,我想访问。任何替代方法有从doinBackground访问UI方法?

解决方案
  

任何替代方法有从doinBackground访问UI方法?

呼叫 publishProgress() doInBackground()。把你的UI更新逻辑 onProgressUpdate()的AsyncTask 的。 onProgressUpdate()将被称为主应用程序线程(又名,UI线程),你打电话后 publishProgress()这里是证明这是一个示例项目。

I am using AsyncTask to upload data to UI. i wrote the code to download data from server in a separate method and i am calling that method from doinBackground. It will give error because UI methods can't access from doInBackground.but, i want to access . any alternative process is there to access the UI method from doinBackground.?

解决方案

any alternative process is there to access the UI method from doinBackground.?

Call publishProgress() in doInBackground(). Put your UI-updating logic in onProgressUpdate() of your AsyncTask. onProgressUpdate() will be called on the main application thread (a.k.a., UI thread) after you call publishProgress(). Here is a sample project demonstrating this.

这篇关于安卓:调用从AsyncTask的doInBackground方法UI线程的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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