Reputation: 180
I use Flutter with the plugin Workmanager. I did not find a way to know if the background task has finished for registerOneOffTask. I had ideas with RxSharedPreferences that I write something from the Workmanager into SharedPreferences and then observe it in my main application but this seems to be quite dirty.
Is there an elegant way to know if the Workmanager task is finished?
Upvotes: 1
Views: 764
Reputation: 809
Before you're executeTask
is about to finish, you can write the result to SharedPreferences
using the task's unique name you will provide.
While the tasks are running, run a 1 second timeout to check the running tasks' result change by observing their SharedPreferences
keys. Once a value of a key changes, remove the entry from SharedPreferences
, and handle the result as needed.
Upvotes: 0