Bolts 介绍
Bolts 是一款底层类库集合, 在后台实现异步操作, 并提供接口反馈当前异步执行的程度 (可以通过接口实现UI进度更新),
最后反馈执行的结果给UI主线程, 与AsyncTask比较: (1)使用的是无大小限制的线程池; (2)任务可组合可级联,防止了代码耦合。
使用
dependencies { compile 'com.parse.bolts:bolts-tasks:1.4.0' compile 'com.parse.bolts:bolts-applinks:1.4.0'}
示例代码
/** Gets a String asynchronously. */ public Task<String> getStringAsync() { // Let's suppose getIntAsync() returns a Task<Integer>. return getIntAsync().continueWith( // This Continuation is a function which takes an Integer as input, // and provides a String as output. It must take an Integer because // that's what was returned from the prevIoUs Task. new Continuation<Integer, String>() { // The Task getIntAsync() returned is passed to "then" for convenience. public String then(Task<Integer> task) throws Exception { Integer number = task.getResult(); return String.format("%d", Locale.US, number); } } ); }
Bolts 官网
https://github.com/BoltsFramework/Bolts-Android
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。