android - 在离线模式下使用 Parse

标签 android parse-platform

我希望在我的 Android 应用程序中使用 Parse。我想为应用程序添加离线支持,以便在离线模式下用户将数据存储在本地,当应用程序连接到互联网时,我们提交数据。

TodoItem todoItem = new TodoItem("Do laundry");
// Set the current user, assuming a user is signed in
todoItem.setOwner(ParseUser.getCurrentUser());
// Immediately save the data asynchronously
todoItem.saveInBackground();
// or 
 todoItem.saveEventually();

当我最终使用保存时,Parse 会等待互联网连接来提交数据。

亲切的问候

最佳答案

2018 年 7 月 13 日更新:由于 parse.com 服务已停止,我将提供来自开源实现 parseplatform.org 的信息。

应用程序将尝试在后台保存它们,如果离线或关闭,下次将尝试保存它们。

Most save functions execute immediately, and inform your app when the save is complete. If you don’t need to know when the save has finished, you can use saveEventually instead. The advantage is that if the user currently doesn’t have a network connection, saveEventually will store the update on the device until a network connection is re-established. If your app is closed before the connection is back, Parse will try again the next time the app is opened. All calls to saveEventually (and deleteEventually) are executed in the order they are called, so it is safe to call saveEventually on an object multiple times. If you have the local datastore enabled, then any object you saveEventually will be pinned as long as that save is in progress. That makes it easy to retrieve your local changes while waiting for the network to be available.

您也可以尝试将它们保存在本地存储中,然后自己保存,这将完成上述工作。

Save eventually Doc

根据 http://parse.com/docs 的文档如果设备离线,您需要调用todoitem.saveEventually()。如果没有连接,您还可以将数据(临时)保存在本地数据存储todoItem.pinInBackground();中,这样您就可以在设备离线时使用保存的内容。

https://parse.com/docs/android_guide#objects-saving-offline

https://parse.com/docs/android_guide#objects-pinning

关于android - 在离线模式下使用 Parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26542877/

相关文章:

android - Ionic Cordova Android : No usable Android build tools found. 最高 30.x 安装版本为 30.0.2;所需的最低版本是 30.0.3

java - Android Java - 下拉微调器始终设置相同的文本,只想更改背景颜色

android - Android 4.4 KitKat 模拟器未启动

ios - Xcode/Parse 未获取测试用户数据 [Parse Starter Kit 1.9.0 + 1.9.1]

swift - 保存要解析的 UITextView 文本

iOS 如何从相机加载照片以解析 Swift

android - Parse.com 是否适合在 Android 中与 SQLite 进行备份/同步?

android - 为什么要使用 TYPE_TEXT_VARIATION_PERSON_NAME (textPersonName)

ios - 行列表中的自定义 iOS "load more"按钮

Android 布局设计器不打开在 IntelliJ 中创建的 XML 文件