我可以链接的任务顺序异步(开始一个previous的AsyncTask完成后)顺序、任务、链接、完成后

由网友(沵旳一句对卟起、伤透叻涐)分享简介:我所做的一切一HTT prequest,屏幕上会出现被锁定了几秒钟,而code正在执行。因此,我用的AsyncTask做我所有的HTT prequest东西在线程同时把一个ProgressDialog让用户知道有事情发生。我最近遇到以下情况,我的htt prequest之一的输入是依赖于结果从previous的htt...

我所做的一切一HTT prequest,屏幕上会出现被锁定了几秒钟,而code正在执行。因此,我用的AsyncTask做我所有的HTT prequest东西在线程同时把一个ProgressDialog让用户知道有事情发生。我最近遇到以下情况,我的htt prequest之一的输入是依赖于结果从previous的htt prequest(+解析)的动作。我不能只是顺序把两者AsyncTask的顺序事业Android将会把他们两个线程,开始第二个没有第一个被完 - 没有合适的输入,我的第二个HTT prequest会崩溃的应用程序。有没有办法,我可以把-处于等待()来强制第二AsyncTask的不启动,直到第一个完成?

Everything I do a httpRequest, the screen will appear to be locked up for a few seconds while the code is executing. Hence I used asynctask to do all my httpRequest stuff in the thread while putting up a ProgressDialog so the user know something is happening. I recently encountered the following situation, the input of one of my httpRequest is dependent on the result from a previous httpRequest (+parse) action. I can't just sequence put the two asynctask sequentially cause android will put them in two threads and starting the second one without the first one being finished -- without an appropriate input, my second httpRequest will crash the app. Is there way I can put-in a wait() to force the second asynctask not to start until the first one finishes?

推荐答案

我也有一些相同的情况下一天。 我已经解决了它这样: 通过你的活动,以异步类的构造函数的引用和执行做背景的功能。现在,在后期执行函数中调用UR活性的公共方法从异步级次执行任务...或者试试这个:

I also had some same situation the other day. I had solved it in this way: Pass the reference of your activity to the constructor of async class and execute the do in background function. Now in post execute function call a public method of ur activity from async class to execute the task again... or try this:

            if (asynclass.getStatus() == android.os.AsyncTask.Status.PENDING) {
                asynclass.execute();
            } else if (RF.getStatus() == android.os.AsyncTask.Status.FINISHED) {
                asynclass = new asyncclass();
                asynclass.execute();
            } else {
                Toast.maketoast(this, "Plz wait", 1).show();
            }

干杯

阅读全文

相关推荐

最新文章