This file contains 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
WorkManager.getInstance().cancelWorkById(uploadWorkRequest.id) | |
WorkManager.getInstance().cancelAllWorkByTag("sometag") |
This file contains 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
WorkManager.getInstance() | |
// These three work requests run in parallel | |
.beginWith(Arrays.asList( | |
filterImageOneWorkRequest, | |
filterImageTwoWorkRequest, | |
filterImageThreeWorkRequest)) | |
// The output from the filter WorkRequests | |
// will be passed as the input of compress WorkRequest | |
.then(compressWorkRequest) | |
.then(uploadWorkRequest) |
This file contains 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
// 1. Create the Constraints | |
val constraints = Constraints.Builder() | |
.setRequiredNetworkType(NetworkType.CONNECTED) | |
.build() | |
// Other supported Constraints | |
val exampleConstraints = Constraints.Builder() | |
.setRequiresBatteryNotLow(true) | |
.setRequiredNetworkType(NetworkType.CONNECTED) | |
.setRequiresCharging(true) |
This file contains 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
class UploadWorker(appContext: Context, workerParams: WorkerParameters) | |
: Worker(appContext, workerParams) { | |
override fun doWork(): Result { | |
try { | |
// Get the input, where this inputData is set when building the WorkRequest | |
val imageUriInput = inputData.getString(Constants.KEY_IMAGE_URI) | |
// Do the work | |
val response = upload(imageUriInput) |