OneTimeWorkRequest
当我使用 android-arch 工作 WorkManager 时,我创建了一些。
我可以WorkStatus
像这样被观察者观看
final WorkManager workManager = WorkManager.getInstance();
final LiveData<List<WorkStatus>> workStatus =
workManager.getStatusesByTag(DailyWorker.DAILY_WORK);
observer = new Observer<List<WorkStatus>>() {
@Override public void onChanged(@Nullable List<WorkStatus> workStatuses) {
Log.d("WorkManager", "onChanged = workStatuses = " + workStatuses);
if (workStatuses == null || workStatuses.size() == 0) {
//DailyWorker.createNewPeriodWork();
} else {
Log.d("WorkManager ", "onChanged = workStatuses.size() = " + workStatuses.size());
for (int i = 0; i < workStatuses.size(); i++) {
Log.d("WorkManager ", "onChanged Work Status Id: " + workStatuses.get(i).getId());
Log.d("WorkManager ", "onChanged Work Status State: " + workStatuses.get(i).getState());
}
}
workStatus.removeObserver(observer);
}
};
workStatus.observe(this, observer);
我的 Android 拱门版本是android.arch.work:work-runtime:1.0.0-alpha02
WorkStatus
但是名单里有很多,一些SUCCEEDED
,一些ENQUEUED
,一些CANCELLED
,而且名单的数量还在不断增加。如何清除工作状态列表?