10

Documentation implies it's scoped per the service class:

A unique job ID for scheduling; must be the same value for all work enqueued for the same class.

However, I have two services with their JOB_ID, and enqueWork() as:

  companion object {
    private const val JOB_ID = 1

    fun enqueueWork(context: Context, action: String) {
      enqueueWork(context, Svc1::class.java, JOB_ID, Intent(action))
    }
  }

and

  companion object {
    private const val JOB_ID = 1

    fun enqueueWork(context: Context, action: String) {
      enqueueWork(context, Svc2::class.java, JOB_ID, Intent(action))
    }
  }

when I start both the services at boot (probably around the same time) Svc2 runs 2x. Changing Svc2's JOB_ID to 2 solves the problem.

If it's NOT scoped by the service class, that's awful as it means every service needs to be aware of the implementation of every other service in the same app.

?

Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134

0 Answers0