我希望在我的 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.
您也可以尝试将它们保存在本地存储中,然后自己保存,这将完成上述工作。
根据 http://parse.com/docs 的文档如果设备离线,您需要调用todoitem.saveEventually()
。如果没有连接,您还可以将数据(临时)保存在本地数据存储todoItem.pinInBackground();
中,这样您就可以在设备离线时使用保存的内容。
关于android - 在离线模式下使用 Parse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26542877/