在 Android 应用程序中缓存远程数据库中的值的正确方法

发布于 2024-12-12 05:46:45 字数 502 浏览 10 评论 0 原文

我很清楚如何使用 Android 与外部服务器进行通信。目前,我正在使用相对较新的 AppEngine Connected Android 项目来完成此操作,一切都运行良好。我唯一关心的是处理服务器的停机时间(如果有的话)和客户端的互联网丢失。

考虑到这一点,我对实现有以下问题:

  • 在 Android 的 SQLite 数据库中缓存值同时仍尝试不断从 Web 应用程序接收数据的标准技术是什么。
  • 当信息可用时,我如何确定我拥有最新信息。
  • 我如何将这一逻辑(确定从哪个逻辑中提取以及数据是否是最新的)包装到 ContentProvider
  • 缓存数据是个好主意吗?或者我应该简单地假设,如果用户没有连接到互联网,那么信息就不容易获得。

I'm well aware of how I can communicate with an outside server using Android. Currently I'm using the relatively new AppEngine Connected Android project to do it, and everything works fairly well. The only thing that I'm concerned with is handling downtime for the server (if at all) and internet loss on the client side.

With that in mind, I have the following questions on an implementation:

  • What is the standard technique for caching values in a SQLite Database for Android while still trying to constantly receive data from the web-application.
  • How can I be sure that I have the most up-to-date information when that information is available.
  • How would I wrap up this logic (of determining which one to pull from and whether or not the data is recent) into a ContentProvider?
  • Is caching the data even that good of an idea? Or should I simply assume that if the user isn't connected to the internet, then the information isn't readily available.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏雨凉 2024-12-19 05:46:45

好消息!有一个 android 构造专门用于执行此类操作,它称为 SyncAdapter。这就是所有谷歌应用程序进行数据库同步的方式。另外,还有一个关于如何使用它的精彩 google IO 视频!它实际上是我的最爱之一。它为您提供了一个非常高层次的概述,说明如何使用称为 REST 的东西来保持远程资源与服务器同步。

Good news! There's a android construct built just for doing this kind of stuff, its called a SyncAdapter. This is how all the google apps do database syncing. Plus there's a great google IO video all about using it! It's actually one of my favorites. It gives you a nice really high level overview of how to go about keeping remote resources synced with your server using something called REST.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文