gpt4 book ai didi

android-architecture-components - 如何清除Android中WorkManager创建的WorkStatus?

转载 作者:行者123 更新时间:2023-12-04 08:45:14 25 4
gpt4 key购买 nike

我创建了一些 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 arch 版本是 android.arch.work:work-runtime:1.0.0-alpha02
但是有很多 WorkStatus在列表中,一些 SUCCEEDED ,一些 ENQUEUED , 一些 CANCELLED ,并且列表的数量不断增加。
如何清除工作状态列表?

最佳答案

您可以调用方法pruneWork()在您的 WorkManager 上清除 List<WorkStatus> .

myWorkManager.pruneWork();

希望能帮助到你!

关于android-architecture-components - 如何清除Android中WorkManager创建的WorkStatus?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50836599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com