Last active
January 14, 2020 06:09
-
-
Save ubarua123/01f65a3b86c80cc6937943f07161691e to your computer and use it in GitHub Desktop.
Adding a work to WorkManager
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static final Constraints NETWORK_CONSTRAINT = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED).build(); | |
// Create a OneTimeWorkRequest using our worker; SampleWorker.class | |
OneTimeWorkRequest sampleWorkRequest = new OneTimeWorkRequest | |
.Builder(SampleWorker.class) | |
.setConstraints(NETWORK_CONSTRAINT) | |
.setBackoffCriteria(BackoffPolicy.LINEAR, OneTimeWorkRequest.DEFAULT_BACKOFF_DELAY_MILLIS, TimeUnit.MILLISECONDS) | |
.build(); | |
// Enqueue | |
WorkManager.getInstance(applicationContext).enqueue(sampleWorkRequest); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment