Status Update
Comments
ra...@google.com <ra...@google.com>
ra...@google.com <ra...@google.com> #2
Hello,
Thank you for reaching out to us with your request.
We have duly noted your feedback and will thoroughly validate it. While we cannot provide an estimated time of implementation or guarantee the fulfillment of the issue, please be assured that your input is highly valued. Your feedback enables us to enhance our products and services.
We appreciate your continued trust and support in improving our Google Cloud Platform products. In case you want to report a new issue, Please do not hesitate to create a new issue on the
Once again, we sincerely appreciate your valuable feedback; Thank you for your understanding and collaboration.
Description
Version used:android.arch.work:work-runtime:1.0.0-beta02
Devices/Android versions reproduced on: Android 8.1
Summary:
A Worker is never scheduled if it was killed by swiping away the app by the user mid-work and then started with enqueueUniqueWork and ExistingWorkPolicy.KEEP.
(If using ExistingWorkPolicy.REPLACE however, it is scheduled appropriately.)
Step-by-step summary:
1. Run the sample app below
2. While the Worker is running, swipe away the app to kill it
3. Run the sample app below
4. The Worker is not scheduled to run again
Detailed step-by-step:
1. Create a hello world Android app
2. Add the following MainActivity.onCreate()
final OneTimeWorkRequest workRequest = new OneTimeWorkRequest.Builder(LogPrinter.class).setBackoffCriteria(BackoffPolicy.LINEAR, WorkRequest.MIN_BACKOFF_MILLIS, TimeUnit.MILLISECONDS).build();
Log.e("Repro", "enqueueUniqueWork");
WorkManager.getInstance().enqueueUniqueWork("name123", ExistingWorkPolicy.KEEP, workRequest);
Where LogPrinter.class is just:
public class LogPrinter extends Worker {
public LogPrinter(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result doWork() {
Log.e("Repro", "doWork start");
SystemClock.sleep(5000);
Log.e("Repro", "doWork returning");
return Result.success();
}
}
3. Start the app. Check the logs and make sure the worker both starts and returns
4. Start the app again. This time, kill the app (by swiping it away in the app switcher) while the worker runs (i.e. after "doWork start" but before "doWork returning"
5. Start the app again.
Expected result:
After max 10 seconds (due to specified backoff time), you should see "doWork start" in the logs.
Actual result:
It never runs as far as I can tell
Primary technical analysis:
In EnqueueRunnable.enqueueWorkWithPrerequisites() in the library, existingWorkSpecIdAndStates specifies the job as "ENQUEUED". Since the policy is KEEP, the method just returns, with needsScheduling = false. But it really should end up true since the job is not running and seemingly never will be enqueued. If you change needsScheduling to true in the debugger, LogPrinter is scheduled as expected.
Let me know if you need further input.