1
votes

In my app I have SQLite database. I want to introduce sync between devices of my users. I want to combine my local SQLite db with cloud Firebase db.

I want my sqlite database to be stored on firebase database when the users are logged in otherwise let it store offline. Any changes to the local database should be reflected on firebase database when logged in. Also if user deletes the local database he/she can retrieve it from firebase database. I just want to use firebase for the synchronization between local database and firebase database.

But i have no clue how to do it. Can anyone please help me with this? My app is in android with java as a backend.

1
This seems very redundant - and there may be a reason to do this but Firebase offers offline persistence so why maintain two totally different datasets when you can just do it with Firebase? Also, Firebase and SQL are unrelated and have totally different storage mechanisms so you would have to add (a lot of?) additional code to make the transition between them. Also, there isn't a direct way to have your sqlite database to be stored on firebase database. Perhaps you can elaborate on your use case so we have a better understanding of why you want to do this? - Jay

1 Answers

1
votes

Rather than storing the sqlite db onto firebase db, you can store the data present in the firebase db based upon the user. when User is performing any operation then store it in local db (sqlite) as well as the firebase db. This will help you to show the data when user is in offline mode. When users has logged out. Delete the local sqlite db and if the user has logged in with the user which already has the data present in the firebase db then sync it with local db.

This will be much easier for you to provide sync between the local sqlite db and firebase db.

If you are providing multiple sign in then you can implement the FCM to provide the sync if data has been changed and update the local db accordingly.

Thank you, Hope it helps