Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Most Effective Way to Sync a ParseObject with Parse.com

I'm currently using Parse.com for my Cloud processing needs in my Android app and I'm trying to figure out the best way to get live updates to ParseObjects via the Parse server. I'd rather not have to get my entire query of ParseObjects every time I want to update the local data with live data (seems very inefficient) as Parse seems to suggest with the use of cached queries.

I already have the BroadcastReceiver and Services in place needed to get Push Notifications from the Parse server but since these always pop up a message I'd rather not go this route either. I already have a sync adapter in place to resolve any conflicts between local and server data so I just need a way to tell my app that an update has been made to a particular ParseObject so it can get updates for that object only (and tell my ContentResolver an update has been made).

EDIT: Below is the code I've tried using what Parse suggests in it's documentation. This code still sends a Notification object to the notification bar even if the 'title' and 'alert' tags in the JSONObject have no values or blank values.

//custom notification data
JSONObject pushObj = new JSONObject();
try {
    pushObj.put("notifVal", "TestValue");
}
catch (JSONException e1) {
    e1.printStackTrace();
    Log.i(TAG, "Error creating Push Notification JSONObject");
    return;
}
//Parse notification object
ParsePush pPush = new ParsePush();
pPush.setData(pushObj);
ParseQuery<ParseInstallation> query = ParseInstallation.getCurrentInstallation().getQuery();
pPush.setQuery(query);
pPush.sendInBackground(new SendCallback() {
    @Override
    public void done(ParseException e) {
        if(e == null)
            Log.i(TAG,"Push Notification Sent");
        else
            Log.i(TAG,"Push Notification Error");
    }
});

EDIT 2: Simply enough all that I was missing was an action tag in the JSONObject...

pushObj.put("action", "com.parse.example.UPDATE");
like image 206
c0deblooded Avatar asked Dec 07 '25 20:12

c0deblooded


1 Answers

keep a last check date in your shared preferences that way when you get a push all you have to do is query against created date and updated date of the object to see either are greater than your last check date. Doing that will then only give you the new or updated items since you last checked

like image 188
tyczj Avatar answered Dec 10 '25 11:12

tyczj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!