WorkManager custom constraint

Viewed 656

Is it possible to set some custom constraints (conditions) on workers?

In my case, I want the worker to be only executed when there are some data available in a table in Room database. I could observe on the database and schedule the worker if the table is not empty, but it would make more sense if I could just set some custom constraints on the worker in such case.

2 Answers

As far as I know you cannot.

The Constraints class is a final class therefore you cannot extend it to add functionality.

You can not use custom constraints with WorkManager at this time.

If you're controlling the database I recommend creating a OneTimeWorkRequest once data has been added to the table.

Related