When working with Workmanager
, I faced the problem, that I wanted to get a single LiveData Object
with the associated tag
. My problem was, that Workmanager
only provided getWorkInfosByTagLiveData
.
Is there a way to get a single LiveData object with the associated tag?
So here is the simple solution:
val singleWorkInfoAsFlow: Flow<WorkInfo> =
WorkManager.getInstance(context).getWorkInfosByTagLiveData("TAG").asFlow().map { it[0] }
val singleWorkInfoAsLiveData: LiveData<WorkInfo> =
WorkManager.getInstance(context).getWorkInfosByTagLiveData("TAG").map { it[0] }
I know that this was not that hard, but I hope I helped some people with this. If someone knows the java version, just provide it here.
Cheers