Reputation: 967
In my Android app I have to keep an existing SQLite database, but in order to sync elements (tasks from a todo-list) to multiple devices I decided to use Firebase Database.
So I'm not enabling Firebase Database offline mode, since I have to use SQLite for that (it's for a college project).
So what I'm doing for writes is that, whenever some data gets added or removed from the local SQLite database that change is also made to the Firebase one.
All this works as expected if the user is connected to the Internet, or even if the user adds a task offline and then becomes online while being on the app.
But if the user adds a task offline, then closes the app and then becomes online in another app, the change doesn't get pushed to the database, even if the user opens my app again.
Any ideas?
Thank you.
Upvotes: 1
Views: 1255
Reputation: 1845
As you did not enable the Firebase Database offline mode all data your app trying to push are not saved in persistent storage, only in memory. Thats why all these data are not pushed to Firebase after application restart.
So you need some synchronization algorithm at application startup which pushes data from you local database to firebase (and vise versa).
For example, you can use timestamp marker (System.currentTimeMillis()) in both local and firebase side which always should be updated on any database change.
Then at application startup you can just check this marker:
if local marker is greater than the remote one - that means that remote database is outdated. So just copy all your local sql database data to firebase.
if remote marker is greater than the local one - just clean local db and download all data from firebase.
if both markers are equal - that means that everything is up to date, do nothing.
Hope this helps :)
Upvotes: 2