10

I'm creating OneTimeWorkRequest with NetworkType.CONNECTED constraint, but even though the device is connected to the internet, the request is still in ENQUEUED state

Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();

OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(SyncWorker.class)
            .setConstraints(constraints)
            .build();

WorkContinuation continuation = mWorkManager.beginUniqueWork("work",
                    ExistingWorkPolicy.KEEP, request);

continuation.enqueue();
minato
  • 2,028
  • 1
  • 18
  • 30
ABOD
  • 113
  • 5

1 Answers1

0

Try this?

Constraints constraints = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build();

OneTimeWorkRequest request = new OneTimeWorkRequest.Builder(SyncWorker.class)
            .setConstraints(constraints)
            .build();

WorkManager.getInstance().enqueue(request);
TomH
  • 2,581
  • 1
  • 15
  • 30
  • Have you debugged into your worker class to see if it is being executed? Is it possible it's not succeeding and therefore retrying itself? – TomH Jul 04 '18 at 09:01
  • facing the same issue with the beta03 release of the library. Worker used to be triggered but since yesterday its not triggered at all and stays in enqueued state. I've set the same network constraint as above and time of 15 minutes. But its a periodic request in my case. – Prasad Pawar Jan 29 '19 at 15:14