允许多个子线程的Asynctak MultiAsynctask

码农软件 · 软件分类 · 手机开发工具 · 2019-04-30 14:13:04

软件介绍

MultiAsynctask,相当于Asynctak,核心不同。系统的AsyncTask在不同版本的API的并发策略是不同的,在Android4.0以上只能运行一个Asynctask。Multiasynctask可以同时做更多的子线程做的事情。默认为5个,且线程池的线程个数是可以修改的。

使用方式如下,基本和系统API相同:

public class LongAsynctask extends MultiAsynctask<Paramer, Updater, Resulter> {

    @Override
    public void onPrepare() {
    }

    @Override
    public Resulter onTask(Paramer... params) {
        Paramer paramer = params[0];
        Logger.i("onTask打印:" + "what:" + paramer.getWhat() + ";value:" + paramer.getValue());
        for (int i = 0; i < 10; i++) {
            paramer.setValue(paramer.getValue() + 1);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            Updater updater = new Updater(paramer.getWhat(), paramer.getValue());
            postUpdate(updater);
        }
        return new Resulter(paramer.getWhat(), paramer.getValue());
    }

    @Override
    public void onUpdate(Updater update) {
        Logger.i("onUpdate打印:" + "what:" + update.getWhat() + ";value:" + update.getValue());
    }

    @Override
    public void onResult(Resulter result) {
        Logger.i("onResult打印:" + "what:" + result.getWhat() + ";value:" + result.getValue());
    }
}

本文地址:https://codercto.com/soft/d/4717.html

Hit Refresh

Hit Refresh

Satya Nadella、Greg Shaw / HarperBusiness / 2017-9-26 / USD 20.37

Hit Refresh is about individual change, about the transformation happening inside of Microsoft and the technology that will soon impact all of our lives—the arrival of the most exciting and disruptive......一起来看看 《Hit Refresh》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具