我可以链接的任务顺序异步(开始一个previous的AsyncTask完成后) [英] Can I chain async task sequentially (starting one after the previous asynctask completes)

查看:124
本文介绍了我可以链接的任务顺序异步(开始一个previous的AsyncTask完成后)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我所做的一切一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();
            }

干杯

这篇关于我可以链接的任务顺序异步(开始一个previous的AsyncTask完成后)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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