Android Workmanager 在固定进程中运行作业 [英] Android Workmanager run job in a fixed process

查看:28
本文介绍了Android Workmanager 在固定进程中运行作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个必须在固定进程中运行的后台任务.我目前正在为此使用 JobIntentService.但是,我想迁移到 WorkManager 以利用基于网络的任务延迟.

I have a background task that has to run in a fixed process. I'm currently using a JobIntentService for this. However, I'd like to migrate to WorkManager to make use of network based task delays.

是否有使用 WorkManager 或任何其他 API 14-28 兼容方式的解决方案?

Is there any solution to this either using WorkManager or in any other API 14-28 compatible way?

推荐答案

WorkManager 2.5.0 新增了一个workmanager-multiprocess 模块来解决这个问题.你可以用实现androidx.work:work-multiprocess:$work_version"

New in WorkManager 2.5.0, there is a workmanager-multiprocess module to solve this problem. You can implement this with implementation "androidx.work:work-multiprocess:$work_version"

要使用它,您可以注册一个新的 WorkManager.Initializer,如本页所述:https://developer.android.com/topic/libraries/架构/工作经理/高级/自定义配置

To use this, you can register a new WorkManager.Initializer as detailed in this page: https://developer.android.com/topic/libraries/architecture/workmanager/advanced/custom-configuration

当您注册此初始化程序时,您的配置需要包括对 .setDefaultProcessName("com.example.app:processName") 的调用.这将使调用发生在正确的过程中.我现在正在测试这个,它似乎有效,但如果有任何问题,我会更新这篇文章.

When you register this initializer, your configurations need to include a call to .setDefaultProcessName("com.example.app:processName"). This will make the calls occur in the correct process. I am testing this out right now, and it seems to be working, but I'll update this post if there are any issues.

这篇关于Android Workmanager 在固定进程中运行作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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