Android线程队列

我想在一个单独的线程上完成一个工作/任务队列,但一次只能处理一个工作.所以不要同时.

有没有内置的Android为此?

谢谢,

编辑:
工作=从数据库获取信息.完成后,使用获取的信息更新UI.

解决方法

你检查过java.util.concurrent.Executors吗?你可以这样做:
final static ExecutorService tpe = Executors.newSingleThreadExecutor();
...
tpe.submit(new Runnable() {
    @Override
    public void run() {
        // your work
    }
}):

它不是特定于Android的,它是jdk5的一部分.

来自doc:

Creates an Executor that uses a single worker thread operating off an unbounded queue. (Note however that if this single thread terminates due to a failure during execution prior to shutdown,a new one will take its place if needed to execute subsequent tasks.) Tasks are guaranteed to execute sequentially,and no more than one task will be active at any given time. Unlike the otherwise equivalent newFixedThreadPool(1) the returned executor is guaranteed not to be reconfigurable to use additional threads.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...