Skip to content

About the start function #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
darshansatra1 opened this issue Jul 29, 2021 · 2 comments
Closed

About the start function #10

darshansatra1 opened this issue Jul 29, 2021 · 2 comments

Comments

@darshansatra1
Copy link

When we call
await FlutterForegroundTask.start( notificationTitle: "Today: $steps steps", notificationText: 'Yesterday: $yesterdaySteps steps', callback: periodicTaskFun, );
Does this call creates a new isolate or is the service still running in the main isolate?

@Dev-hwang
Copy link
Owner

@darshansatra1

When the FlutterForegroundTask.start function is called, a new isolate is created separate from the main isolate. The isolate of dart has a separate memory area unlike the threads used in other languages. Therefore, periodicTaskFun is executed in the new isolate and the event is called periodically by creating a background method channel through FlutterForegroundTask.initDispatcher function.

If you want to share data with an isolate that has separate memory areas, try the sqflite plugin.

As I am still learning, it may not be a perfect answer, but I hope it helps you :)

@darshansatra1
Copy link
Author

Yaa I faced the issue in Hive, since Hive doesn't support multi-threading. So I switched to object box which had better performance than sqflite and also supports multi-threading.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants