WorkManager custom constraint
Asked Answered
A

2

8

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.

Awhirl answered 16/11, 2018 at 10:40 Comment(0)
A
0

As far as I know you cannot.

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

Audwen answered 8/4, 2019 at 19:29 Comment(0)
R
0

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.

Rieth answered 4/11, 2021 at 15:18 Comment(1)
Any chance this could be added in a future release of work manager?Polyester

© 2022 - 2024 — McMap. All rights reserved.