-
Notifications
You must be signed in to change notification settings - Fork 26
Flutter background processing
Matej Drobnič edited this page Dec 28, 2020
·
3 revisions
Since most of the watch logic is being executed in the background when the app is not open, Cobble also has background flutter side. All code in the background folder is executed in the separate isolate.
How background works:
- When user opens app normally,
BackgroundSetupControl().setupBackground
is called. This sends method reference of themain_background
to the native side via Flutter. Native saves that reference. - When native background service of the app is started, separate flutter instance is created and previously-saved reference to the main_background is executed.
-
main_background
registers all needed pigeon callbacks - Whenever some event that needs processing occurs (for example when user changes his/hers calendar and needs sync), native sends pigeon to the background Flutter instance.
Notes:
- Background instance is completely isolated from the UI flutter instance. No variables or object instances are shared.
- To send messages from UI to background isolate, UI must send a pigeon to the native which then proxies the message back to the background isolate
- Due to SQLite's spotty support for multiple isolates, database is read-only from the UI isolate. If UI needs to change the database it needs to send a message to the background isolate through above mentioned process and then background isolate updates the DB accordingly.