One time job on WorkManager not running on some devices

Viewed 307

job scheduled using WorkManager on some devices (1 case out of 100) does not get executed at all. I schedule jobs:

val constraints = Constraints.Builder()
    .setRequiredNetworkType(NetworkType.CONNECTED)
    .build()
WorkManager.getInstance(applicationContext)
    .enqueueUniqueWork(SessionRecordReportingWorker.WORK_TAG, ExistingWorkPolicy.APPEND_OR_REPLACE,
            OneTimeWorkRequest.Builder(SessionRecordReportingWorker::class.java)
                    .addTag(SessionRecordReportingWorker.WORK_TAG)
                    .setConstraints(constraints)
                    .setBackoffCriteria(BackoffPolicy.EXPONENTIAL, 30, TimeUnit.SECONDS)
                    .build());

When I do APPEND_OR_REPLACE, the new job does flush whole database, so it is not the problem. New job will remove previous, but send all data. The newest stable version of workmanager library is used

implementation "androidx.work:work-runtime-ktx:2.5.0"

I have asked the customer all questions I could think about: is background sync disabled, is power optimization on, is power optimization on on this app, is battery low. However, when test this on my Android 11 - everything works as expected. Job gets executed and sent to server. Client executes normal web requests when on app (so his network is connected), then log/record of all important actions should be reported using workmanager. However in this case it is not executed/sent. Can you point be to potential cause of it?

1 Answers

WorkManager is not reliable:

https://dontkillmyapp.com/

Basically, you can stop here...

Besides that you can see what is happening with the work by debugging the JobScheduler, but as it is not happening in your environment.. I do not know what to advise you.

https://developer.android.com/topic/libraries/architecture/workmanager/how-to/debugging

Use adb shell dumpsys jobscheduler

You need to check in the dump:

  • If there is currently scheduled tasks
  • History of executed tasks
  • Satisfied vs Unsatisfied constraints
  • App Standby Bucket
  • Available milliseconds for the Network/Quotas
Related