0

I am trying to learn WorkManager for Android using codeLab documentation. I app crash when I try to test functionality of beginUniqueWork(Ensure Unique Work)

I just implement beginUniqueWork and test app with selecting image multiple time.

Code I writre in aplyBlur() in ViewModel class is:

  void applyBlur(int blurLevel) {


    WorkContinuation continuation = mWorkManager
            .beginUniqueWork(IMAGE_MANIPULATION_WORK_NAME,
                    ExistingWorkPolicy.REPLACE,
                    OneTimeWorkRequest.from(CleanupWorker.class));

    // Add WorkRequests to blur the image the number of times requested
    for (int i = 0; i < blurLevel; i++) {
        OneTimeWorkRequest.Builder blurBuilder =
                new OneTimeWorkRequest.Builder(BlurWorker.class);

        // Input the Uri if this is the first blur operation
        // After the first blur operation the input will be the output of previous
        // blur operations.
        if ( i == 0 ) {
            blurBuilder.setInputData(createInputDataForUri());
        }

        continuation = continuation.then(blurBuilder.build());
    }

    // Add WorkRequest to save the image to the filesystem
    OneTimeWorkRequest save =
            new OneTimeWorkRequest.Builder(SaveImageToFileWorker.class)
                    .build();
    continuation = continuation.then(save);

    continuation.enqueue();
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
AmmY
  • 1,821
  • 1
  • 20
  • 31

1 Answers1

2

This is https://issuetracker.google.com/79550068. It has been fixed now and the fix is available in alpha02 of WorkManager, which is out now.

Community
  • 1
  • 1
SumirKodes
  • 551
  • 2
  • 6
  • This is fixed in `alpha02`. Here is the release notes: https://developer.android.com/jetpack/docs/release-notes – Rahul May 25 '18 at 21:27