5

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
F43nd1r
  • 7,690
  • 3
  • 24
  • 62

3 Answers3

1

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.

Scott Driggers
  • 189
  • 3
  • 9
0

What about this approach:


        <service
                android:name="androidx.work.impl.background.systemjob.SystemJobService"
                android:process=":worker"/>

Just put the declaration into your Manifest and ManifestMerger creates a final merged Manifest with android:process=":worker" (worker is a name of non-main process, can be another one)

ultraon
  • 2,220
  • 2
  • 28
  • 27
-1

have a look at this work manager for network calls sample

stevandoh
  • 47
  • 1
  • 1