Answer the question
In order to leave comments, you need to log in
How to clear WorkManager activity status after read in android?
Greetings!
When using WorkManager, I encountered the problem that the status of the operation is not removed from the read field.
Here is the initialization of the operation
private fun saveCashCommandSchedule() {
val constraints = Constraints.Builder()
.setRequiredNetworkType(NetworkType.CONNECTED)
.build()
val work = OneTimeWorkRequestBuilder<WorkSynchronizeCashSchedule>()
.setConstraints(constraints)
.build()
WorkManager.getInstance().enqueueUniqueWork("send_cash_schedule", ExistingWorkPolicy.REPLACE, work)
}
fun subscribeWorkScheduleCash(lifecycle: Lifecycle) {
WorkManager.getInstance().getWorkInfosForUniqueWorkLiveData("send_cash_schedule").observe({
lifecycle
}, { states ->
states?.forEach {
if (it != null && it.state == WorkInfo.State.SUCCEEDED) {
//TODO вот этой строки хотелось бы избежать
// WorkManager.getInstance().pruneWork()
loadData()
[email protected]
}
}
})
}
Answer the question
In order to leave comments, you need to log in
Try adding a keepResultsForAtLeast call with a duration of 1 millisecond to the OneTimeWorkRequestBuilder.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question