- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在尝试实现最新的 WorkManager-alpha10 ListenableFuture 以处理流程完成时遇到一些问题。
现在我的 JobOrganizer 类中有以下内容
private fun enqueueDownloadWork(): ListenableFuture<Void> {
val work = WorkManager.getInstance()
.beginWith(dwdTypologiesJob)
.then(dwdElementsJob)
.then(dwdAnomaliesJob)
return work.enqueue()
}
private fun createDownloadWorkRequests() {
dwdTypologiesJob = OneTimeWorkRequestBuilder<DWDAnomalyTypesJob>()
.addTag("download_typologies_work")
.build()
dwdElementsJob = OneTimeWorkRequestBuilder<DWDElementsJob>()
.addTag("download_elements_work")
.build()
dwdAnomaliesJob = OneTimeWorkRequestBuilder<DWDAnomaliesJob>()
.addTag("download_anomalies_work")
.build()
}
fun downloadData(): ListenableFuture<Void> {
createDownloadWorkRequests()
return enqueueDownloadWork()
}
这是我的电话,谁应该听取完成事件。
val listenable = JobOrganizer.downloadData()
listenable.addListener({
Log.d("Listenable", "Did something 1");
}, {
Log.d("Listenable", "Did something 2");
})
我仍然不知道 Runnable 和 Executor 如何处理这个函数。谁能解释一下?
谢谢
最佳答案
你需要同时实例化Runnable和Executor,比如当你想在当前线程直接执行Runnable时:
.addListener(
object:Runnable {
override fun run() {
Log.d("Listenable", "Did something 1");
}
},
object:Executor {
override fun execute(command: Runnable?) {
command?.run()
}
}
您可以在 https://developer.android.com/reference/java/util/concurrent/Executor 上找到有关执行器的更多示例
关于android - WorkManager alpha10 ListenableFuture 用法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52876776/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 6年前关闭。 Improve this qu
我有实体: @Entity @Table(name = "CARDS") public class Card { @ManyToOne @JoinColumn(name = "PERSON_I
我正在尝试计算二维多边形的表面法线。我正在使用 OpenGL wiki 中的 Newell 方法来计算表面法线。 https://www.opengl.org/wiki/Calculating_a_S
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 7 年前。 Improve
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 9 年前。 Improve this
我这里有以下 XML: Visa, Mastercard, , , , 0, Discover, American Express siteonly, Buyer Pay
即将发生的 Google 政策变更迫使我们实现一个对话框,以通知欧盟用户有关 Cookie/设备标识符用于广告和分析的情况。我只想向欧盟用户显示此对话框。我不想使用额外的权限(例如 android.p
本文分享自华为云社区《华为大咖说 | 企业应用AI大模型的“道、法、术” ——道:认知篇》,作者:华为云PaaS服务小智。 本期核心观点 上车:AGI是未来5~10年内,每个人都无法回避的技
我有一个与酒精相关的网站,需要先验证年龄,然后才能让他们进入该网站。我使用 HttpModule 来执行此操作,该模块检查 cookie,如果未设置,我会将它们重定向到验证页面。我验证他们的年龄并存储
在欧盟,我们有一项法律,要求网页请求存储 cookie 的许可。我们大多数人都了解 cookie 并同意它们,但仍然被迫在任何地方明确接受它们。所以我计划编写这个附加组件(ff & chrome),它
以下在 C 和/或 C++ 中是否合法? void fn(); inline void fn() { /*Do something here*/ } 让我担心的是,第一个声明看起来暗示函数将被定义
我是一名优秀的程序员,十分优秀!