Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Workmanager run job in a fixed process

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.

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

like image 358
F43nd1r Avatar asked Nov 18 '22 05:11

F43nd1r


1 Answers

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"

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

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.

like image 132
Scott Driggers Avatar answered Dec 03 '22 21:12

Scott Driggers