Unable to locate Isolate to kill it
After spawning a new Isolate, it will continue to work even after the app is killed (tested), Example: void startIsolate() async { await FlutterIsolate.spawn(isolate1, "hello"); } void isolate1(String arg) { Timer.periodic(Duration(seconds:1),(timer)=>print("Hello")); } void stopIsolate(){ // what should be the code here? how to catch it after killing the app?
} The issue is after the app is relaunched the isolates keep on running, I'm unable to catch it anymore, is there a way to find the current running isolate (not the main)? FlutterIsolate.current returns the main isolate not isolate1, after killing the app, isolate1 only stops by going to mobile setting->appSetting-> force stop
You can use the instance returned by await FlutterIsolate.spawn(isolate1, "hello"); and then call kill() on that.
The main problem would be: where do you call stopIsolate()?
I am using the killAll() API at app start, not without its problems: https://github.com/rmawatson/flutter_isolate/issues/107