-
-
Save virendersran01/802a119e189d077e516ffb9abe99af31 to your computer and use it in GitHub Desktop.
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 class UploadWorker extends Worker { | |
public UploadWorker( | |
@NonNull Context context, | |
@NonNull WorkerParameters params) { | |
super(context, params); | |
} | |
@Override | |
public Result doWork() { | |
// Do the work here--in this case, upload the data to the server. | |
uploadData() | |
// Indicate whether the task finished successfully with the Result | |
return Result.success() | |
} | |
} | |
// define periodic work request and start it | |
PeriodicWorkRequest uploadWorkRequest = | |
new PeriodicWorkRequest.Builder(UploadWorker.class, 15, TimeUnit.MINUTES) | |
// setting a backoff on case the work needs to retry | |
.setBackoffCriteria(BackoffPolicy.LINEAR, PeriodicWorkRequest.MIN_BACKOFF_MILLIS, TimeUnit.MILLISECONDS) | |
.build(); | |
WorkManager.getInstance(mContext).enqueue(uploadWorkRequest); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment