Open navaronbracke opened 2 years ago
This is a great idea.
Why would you want to intercept - e.g. what would you like to do as a developer with the information? Reschedule another task?
Well, I had a task indicator that would show progress (pending, running, done) and I was looking for a way to indicate a cancelled state.
So your use case is just to show when things have failed. How would you handle the case when the task runs in the background but your main application is not visible?
In my use case, I let the background task write the progress information to a database (which uses dart:ffi since it needs to be accessible across both the foreground Flutter Engine & the background Flutter Engine, which don't live in the same engine group). I don't show any updates when the app is in the background. When the application is in the foreground, I just observe the database for updates.
Version
workmanager: 0.5.0
Describe the error
When a task is cancelled by WorkManager, there is no way to intercept the cancellation.
Steps to reproduce
1) Start a one off task with a network constraint
2) while the task is running, disconnect from the internet 3) the task is cancelled
Proposal
The plugin should expose a stream of cancellation events for the scheduled tasks. There could be an
EventSink
on the native side that gets its events from invokinghttps://developer.android.com/topic/libraries/architecture/workmanager/how-to/managing-work#onstopped_callback
in the worker implementation. The event should have enough information so that a developer can know which task was cancelled. Thus an event would at least need the unique name (and the original input data?)
Output of
flutter doctor -v