Link Android Room Database with Firebase Realtime Database

Pierre Ghaly picture Pierre Ghaly · Apr 23, 2018 · Viewed 8.3k times · Source

I am using Android Room Database for creating the database for my android app. It works perfectly for me locally but I cannot link to a server to have it online as well. I am using Firebase for Authentication. I am trying to use Firebase Realtime Database to save the whole database object from Room and load the correct database on app startup according to the authenticated user.

I want to ask if this is possible at all? and if I can just save a whole instance of Room database or I need to re-create the database on Firebase and save my data item by item?

I also can't seem to be able to get access to the database data of Room, as when I get an object of the AppDatabase class it doesn't really pass the data. And I don't know how should do the opposite, to assign the data retrieved from Firebase later to the local data saved?

Also if it's not possible with Firebase, do you have any recommendation for some other server I can use with Room?

Answer

Pierre Ghaly picture Pierre Ghaly · Apr 23, 2018

After a lot of researches and looking desperately for an answer here's what I reached:

  • Firebase already got a straight forward way to create the database and host it online. (I had my database already created so was trying to save time, but creating it from scratch using Firebase Realtime Database was a lot faster)
  • Room Database is quite perfect if you are planning to save your database locally and offline (Up to the post date)