Change theme
Help
Press space for more information.
Show links for this issue (Shortcut: i, l)
Copy issue ID
Previous Issue (Shortcut: k)
Next Issue (Shortcut: j)
Sign in to use full features.
Vote: I am impacted
Notification menu
Refresh (Shortcut: Shift+r)
Go home (Shortcut: u)
Pending code changes (auto-populated)
View issue level access limits(Press Alt + Right arrow for more information)
Unintended behavior
View staffing
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.