问题描述
我正在使用 Android Room Database 为我的 Android 应用创建数据库.它在本地非常适合我,但我无法链接到服务器以使其在线.我正在使用 Firebase 进行身份验证.我正在尝试使用 Firebase 实时数据库 从 Room 保存整个数据库对象,并根据经过身份验证的用户在应用启动时加载正确的数据库.
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.
我想问一下这是否可能?如果我可以只保存 Room 数据库的整个实例,或者我需要在 Firebase 上重新创建数据库并逐项保存我的数据?
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?
我似乎也无法访问 Room 的数据库数据,因为当我获取 AppDatabase 类的对象时,它并没有真正传递数据.而我不知道应该如何做相反的事情,将稍后从 Firebase 检索到的数据分配给保存的本地数据?
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?
此外,如果 Firebase 无法实现,您对我可以与 Room 一起使用的其他服务器有什么建议吗?
Also if it's not possible with Firebase, do you have any recommendation for some other server I can use with Room?
推荐答案
经过大量研究并拼命寻找答案后,我得出了以下结论:
After a lot of researches and looking desperately for an answer here's what I reached:
- Firebase 已经有了一种直接的方法来创建数据库并在线托管它.(我已经创建了我的数据库,因此试图节省时间,但使用 Firebase 实时数据库从头开始创建它要快得多)
- 如果您打算本地和离线保存您的数据库,Room Database 是非常完美的(截至发布日期)
- 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)
这篇关于将 Android Room 数据库与 Firebase 实时数据库关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!