1

In my app, I have an SQLite/Room database. I want to introduce synchronisation between the devices of my users. I want to combine my local SQLite/Room DB with a cloud Firebase DB.

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

How can I do it? My app is in Android with Java as a backend.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

0

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

I don't see any reason why you would add an additional local database to your application, since both Firestore and the Realtime Database have their own offline persistence mechanism. However, you can implement such a feature but you should take into consideration that the entire mechanism of synchronization should be managed by you.

I want my SQLite database to be stored on the Firebase Database when the users are logged in otherwise let it store offline.

This can be simply done without a local database. How can you achieve that? Simply by attaching an auth state listener to track the user auth state. This means that when you're using Firestore, you can specify the source for reading the data. For example, if the user is authenticated you can read the data from Source.SERVER, otherwise from Source.CACHE.

Also if the user deletes the local database he/she can retrieve it from Firebase Database.

There's currently no API that does that. You should implement your own mechanism. You should track the user when it deletes the database and then take some actions accordingly.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193