'How fetch only new data from Parse.com

I'm building an Android app and a back office in PHP. In my back office, an administrator can create and edit some objects (like events, activities,...)

There is a lot of datas (hundred of events, hundred of activities,...).

My question is : The first time running, the Android app will fetch all the datas (all events, all activities). Then the administrator in the back office edit or add an event. What is the best way for the Android app, to fetch only the latest datas ?

Is the best way to push all single new data (or edited data) ? Like : the event A is edited, send push to ALL devices to notify that the event A is edited ?



Solution 1:[1]

You have more than one question. I will answer the one on the title:

ParseObjects always have a createdAt and an updatedAt field that you can order your results by. Also, you can limit how many results a ParseQuery returns (see PHP documentation and Android documentation).

If, say, you want to fetch up to 50 events, newest first, you could do the following in PHP, assuming that ordering by createdAt timestamp works for you:

$q = new ParseQuery("Event");
$q->limit(50);
$q->descending("createdAt");
$events = $q->find();

If you want to get up to 50 events newer than a specific date/time, you could do the following (see PHP documentation for DateTime). This might be useful if, for example, you already loaded some events and want to "refresh":

$date = new DateTime(/*Valid timestamp here*/);
$q = new ParseQuery("Event");
$q->limit(50);
$q->descending("createdAt");
$q->greaterThan("createdAt", $date);
//You can also use $q->greaterThanOrEqualTo("createdAt", $date);
$events = $q->find();

I provided PHP examples since that's what I know how to use for Parse but you can do the same in Android.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 lipusal