Skip to content
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

Issue using Sembast in Background Notification - Android #356

Open
jamescardona11 opened this issue Apr 21, 2023 · 6 comments
Open

Issue using Sembast in Background Notification - Android #356

jamescardona11 opened this issue Apr 21, 2023 · 6 comments

Comments

@jamescardona11
Copy link

Hello, I hope everything is going well.

I have a question; I have a Sembast instance in foreground state to watch all information from the database.
When I change the app background state and receive a notification from Firebase, I save some data in Sembast, I saw in the documentation Firebase Background Notification works like an Isolate.
The data is saved to Sembast with that, but the main app can't emit that new data received from the notification background.
If I continue sending information in foreground, the main isolate is emitted data from Sembast.

When I do a HotReload, the data from background is emitted.
I want to drop a video to show the behavior that only happens in Android.

I tried to stop and restart the subscription in the main Isolate, and is not emitting data that is received from the notification background.

Screen.Recording.2023-04-21.at.4.43.14.PM.mp4
@alextekartik
Copy link
Collaborator

Unfortunately I don't have a good solution. sembast is definitely not safe in background isolate. I would personally use a separate solution for the notification:

  • When in a background isolate, write the notifications in a file (or even in a separate sembast database), i.e. the background isolate would only access the storage in write mode
  • In the foreground, when starting, check the notifications file or database (read mode)

@jamescardona11
Copy link
Author

jamescardona11 commented Apr 24, 2023

Unfortunately, creating a second table and reading from there when the app returns to the foreground doesn't work;
In some cases everything seems to work well, in other moments I read the background table and receive nothing.

I'll try another solution and leave my answer here.

When you said read mode, is it something special?

@x3rud
Copy link

x3rud commented Sep 21, 2023

@jamescardona11 did you find any solution for that? I have the same problem

@jamescardona11
Copy link
Author

@x3rud no directly with Sembast; I made a mix following the suggestion from Alex about writing in a temporal file and read/write when the app is open again.

@x3rud
Copy link

x3rud commented Sep 22, 2023

Thank you. The strange thing is that the data is being stored on the database.

@alextekartik have you thought about a hypothetical solution in recent months?

@alextekartik
Copy link
Collaborator

The issue is that since every isolate has its own copy in memory content might be different with what is store in the database. I don't have a good solution for this unfortunately...sorry.

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

3 participants