AndroidDev
AndroidDev

Reputation: 16385

Using Parse in offline mode

I am looking to use Parse in my android application. I want to add offline support to the application, such that in offline mode the user stores the data locally, and when the application gets connected to the internet, we submit the data.

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();

When i use save eventually, will Parse wait for the internet to connect to submit the data.

Kind Regards

Upvotes: 2

Views: 2976

Answers (1)

Cornel
Cornel

Reputation: 314

Update 13-07-2018: Since the parse.com service was discontinued, I will provide the info from the parseplatform.org, the opensource implementation.

The app will try to save them in the background, and if it's offline, or closed, will try next time to save them.

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.

You could also try to save them in local storage, and then save by yourself, which will do the work mentioned above.

Save eventually Doc

According to the documentation from http://parse.com/docs you need to call todoitem.saveEventually() if the device is offline. In case there is no connection, you might also save the data (temporary) in the local data store todoItem.pinInBackground();, so you can work with what you saved when the device is offline.

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

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

Upvotes: 3

Related Questions