Closed maxmitz closed 1 year ago
In the example you gave, what exactly happens - does the foreground/UI stop responding, or the isolate task never starts/completes, or the completion signal is never received on the main isolate?
This is not clear because it is not possible to set break points in the release mode. My guess is that isolate works extremely slowly in the background because it continues faster when you open the app again. My derivation from this is that the UI responses but a completion signal cannot be received because it did not finish.
I posted this in the flutter sdk as issue and I got the response that Isolates should be used for multithreading but not for background processes (https://github.com/flutter/flutter/issues/116715#issuecomment-1342702288). I think it is possible to close this issue.
Sorry I originally misunderstood what you meant by "background" (I misread and thought you were referring to work done in a background isolate while the app was still in the foreground, not while the app itself is backgrounded).
Code running in isolates is still considered "app code" by Android/iOS so you have no control over the priority allocated to the thread (in fact there are no guarantees that the app won't be killed entirely while in the background, which includes code running in isolates).
If you need to run long-running tasks while the app is in the background you will need to use background task (iOS) or work manager (Android). The referenced work_manager
plugin for flutter is your best bet.
I used flutter_isolate to do computational exhausting operations in the background. I have a problem that for iOS and Android in release mode the operation more or less stops when I move it to the background.
Did I do something wrong or is the plugin not able to do this?
Thanks in advance and thanks for working on this plugin!
A small example to test it:
main.dart