在机器人在做doinbackground UI任务() [英] Doing UI task in doinbackground() in Android

查看:144
本文介绍了在机器人在做doinbackground UI任务()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法做UI任务中的AsyncTask的doinbackground()。我深知这是更好地做到这一点在onPostExecute方法。但是,在我的情况,因为我需要使用可重复使用的警报,能够访问用户界面在我doinbackground可以节省我很多时间。也就是说,我需要调整code。在46的地方,但能够做到这一点,在doinbackground将需要在一个地方的变化。

Is there a way to do UI task in the doinbackground() of the AsyncTask. I am well aware it is better to do it in onPostExecute method. But in my case since I am need to use a reusable alert, being able to access the UI in my doinbackground would save me a lot of time. That is, I need to tweak the code in 46 places but being able to do this in the doinbackground will need the change in just one place.

在此先感谢

推荐答案

希望这将解决您的问题。

Hope this will solve your problem

    onPreExecute() {
       // some code #1
    }

    doInBackground() {
        runOnUiThread(new Runnable() {
                    public void run() {
                        // some code #3 (Write your code here to run in UI thread)

                    }
                });
    }

    onPostExecute() {
       // some code #3
    }

这篇关于在机器人在做doinbackground UI任务()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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