仅在远程数据库(Android Studio)发生更改时更新本地数据库
我正在使用OkhttpClient从远程数据库获取数据,并向用户显示响应。 用户将永远不会更改远程数据库。我现在正在实现SQL Lite Local DB,因为我认为使用API始终使用相同的数据是不好的(因为用户将经常发送请求,并且远程数据库中的数据更改将是最小的)。我的问题是,当远程数据库更新/更改时,如何更新本地数据库。
我已经读到,定期更新本地DB是不好的做法。那么,最好的方法是什么?
I'm using OkHttpClient to fetch data from remote DB and display the response to the user.
The user will never make changes to the remote DB. I'm now implementing SQL lite local DB, since I don't think it's good to use APIs to fetch the same data all the time (since the user will send requests frequently and the data change in remote DB will be minimal). My question is how can I update my local DB when remote DB updates/changes.
I have read that updating local DB periodically is bad practice. so, what's the best way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您无法监视远程DB“除非您定期拨打API,否您可以使用该应用程序更改远程数据库并将其同步。您需要使用实时数据库
You have no way to spy on the remote DB "unless you make API calls on a regular basis you need to sample it every few minutes to truly know if it has changed" OR "you assume that every time you use the app your remote DB changed and sync it" if even this is not a viable solution for you and you need it as it updates. You need to use a Realtime DB
使用socket.io。远程数据库发生变化时,它会自动将数据发送到应用程序。
查看以下链接: https://socket.io/blog /本地插入 - io和android/
Use socket.io.When something changes in remote db, it sends the data to the app automatically.
Take a look at the following link: https://socket.io/blog/native-socket-io-and-android/