Reputation: 65
I am trying to develop an android application while storing database on parse server. Everything works fine but problem is with application offlime usage. Is there any way i can store data locally including log in details and fetch data from server only when updated. plz give me some suggestion examples would be better. Thanks
Upvotes: 0
Views: 1277
Reputation: 224
You need to use Localdatastore.
in your android app enable it.
Parse.Configuration config = new Parse.Configuration.Builder(this)
.applicationId("XXXXXXXXXXX")
.clientKey("XXXXXXXXXXX")
.server("https://api.serverused.com/")
.enableLocalDataStore() // Acticate it here
.build();
Parse.initialize(config); //
This is how to save the object or list of objects offline
ParseQuery<ParseObject> query = ParseQuery.getQuery(“GameScore");
query.getInBackground("xWMyZ4YE", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// object will be your game score so save it offline
object.pinAllInBackground();
} else {
// something went wrong
}
}
});
This is how to get your localdata
ParseQuery<ParseObject> query = ParseQuery.getQuery(“GameScore");
query.fromLocalDatastore();
query.getInBackground("xWMyZ4YE", new GetCallback<ParseObject>() {
public void done(ParseObject object, ParseException e) {
if (e == null) {
// object will be your game score
} else {
// something went wrong
}
}
});
If you are saving a list of objects, generally used with findInBackground, you will need to use
ParseObject.pinAllInBackground(objects);
Hope this helps and check the docs Parse LocalDataStore
Upvotes: 3