在机器人在做doinbackground UI任务()机器人、任务、doinbackground、UI

由网友(谁的心动 Who's heart)分享简介:有没有办法做UI任务中的AsyncTask的doinbackground()。我深知这是更好地做到这一点在onPostExecute方法。但是,在我的情况,因为我需要使用可重复使用的警报,能够访问用户界面在我doinbackground可以节省我很多时间。也就是说,我需要调整code。在46的地方,但能够做到这一点,在...

有没有办法做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
    }
阅读全文

相关推荐

最新文章