在Android 1.6的Queing多任务异步 [英] Queing multiple Async Tasks in Android 1.6

查看:108
本文介绍了在Android 1.6的Queing多任务异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行code和两个任务的doInBackGround部分相​​同块中的两个异步任务同时运行,这是造成问题。根据Android 1.5的异步任务下面链接的文章被自动执行顺序qeued,但对于Android 1.6的辗转此功能。所有异步任务queing资源,我发现使用的倡导者,但线程池这仅适用于蜂巢。以正确的方式有什么建议来处理这个问题?

I am run two Async Tasks in the same block of code and the doInBackGround portions of the two tasks are running simultaneously, which is causing problems. According to the article linked below in android 1.5 Async Tasks were automatically qeued by order of execution, but this feature was removed for Android 1.6. All of the Async Task queing resources I've found advocate using threadPool but this is only available for Honey Comb. Any suggestions on the right way to handle this problem?

文章:的AsyncTask 的并行执行

推荐答案

AsyncTask.get()会导致调用线程块执行,等待它完成,你可以做这样的事情:

AsyncTask.get() will cause the calling thread block execution and wait for it finish, you can do something like this:

myAsyncTask1.execute();
myAsyncTask1.get();
myAsyncTask2.execute();

这将保证第二AsyncTask的是一日一结束,请记住,AsyncTask.get()块线程执行,因此,如果你把这个在UI线程,你可能会得到ANR例外。

This will guarantee the 2nd AsyncTask is executed after 1st one finish, bear in mind that AsyncTask.get() block thread execution, so if you call this in UI thread,you will probably get ANR exception.

这篇关于在Android 1.6的Queing多任务异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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