安卓:调用从AsyncTask的doInBackground方法UI线程的方法 [英] Android : Calling the methods on UI thread from AsyncTask doInBackground method
问题描述
我使用的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屋!