Jan Maděra
Jan Maděra

Reputation: 546

Android WorkManager - get unfinished works from WorkManager

is there any way to get all unfinished works from WorkManager from android-jetpack? I know you can get Works by id/tag. But cannot find some way to get all unfinished Works? Thanks for answers :)

Upvotes: 0

Views: 1109

Answers (1)

pfmaggi
pfmaggi

Reputation: 6506

If what you want to achieve is to maintain the order of your work requests, an approach is to use an UniqueWorkRequest using as ExistingWorkPolicy the APPEND one. This creates for you a chain of work:

WorkManager.getInstance(context).enqueueUniqueWork("unique name", ExistingWorkPolicy.APPEND, myOneTimeWorkRequest)

You can find more information in WorkManager's Unique Work guide. Keep in mind that if you cancel a work request in the chain or return failure from your worker, the all chain is cancelled or marked as failed.

Upvotes: 1

Related Questions