Skip to content

Commit ba5d4b1

Browse files
natario1flovilmart
authored andcommitted
Android docs for ParsePush.setPushTime() and changes in ParseQuery (#440)
* Update ParseQuery docs for Local Datastore * Update ParsePush docs with setPushTime()
1 parent ba66c50 commit ba5d4b1

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

_includes/android/push-notifications.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,21 @@ wpPush.sendPushInBackground();
319319

320320
## Scheduling Pushes
321321

322-
Sending scheduled push notifications is not currently supported by the Android SDK. Take a look at the [REST API]({{ site.baseUrl }}/rest/guide/#scheduling-pushes), [JavaScript SDK]({{ site.baseUrl }}/js/guide/#scheduling-pushes) or the push console on your Parse Dashboard.
322+
You can schedule a push in advance by specifying a push time with `ParsePush.setPushTime(long)`. For example, if a user schedules a game reminder for a game tomorrow at noon UTC, you can schedule the push notification by sending:
323+
324+
```java
325+
long tomorrowTime = ...; // in seconds
326+
327+
// Send push notification with expiration interval
328+
ParsePush push = new ParsePush();
329+
push.setPushTime(tomorrowTime);
330+
push.setMessage("You previously created a reminder for the game today");
331+
push.sendPushInBackground();
332+
```
333+
334+
If you also specify an expiration interval, it will be calculated from the scheduled push time, not from the time the push is submitted. This means a push scheduled to be sent in a week with an expiration interval of a day will expire 8 days after the request is sent.
335+
336+
The scheduled time cannot be in the past, and can be up to two weeks in the future.
323337

324338
## Receiving Pushes
325339

_includes/android/queries.md

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,8 @@ You can query from the local datastore using exactly the same kinds of queries y
311311

312312
## Caching Queries
313313

314+
### With Local Datastore enabled
315+
314316
It's often useful to cache the result of a query on a device. This lets you show data when the user's device is offline, or when the app has just started and network requests have not yet had time to complete. The easiest way to do this is with the local datastore. When you pin objects, you can attach a label to the pin, which lets you manage a group of objects together. For example, to cache the results of the query above, you can call `pinAllInBackground` and give it a label.
315317

316318
```java
@@ -340,7 +342,40 @@ query.findInBackground(new FindCallback<ParseObject>() {
340342
});
341343
```
342344

343-
Now when you do any query with `fromLocalDatastore`, these objects will be included in the results if they still match the query.
345+
Now when you do any query with `fromLocalDatastore`, these objects will be included in the results if they still match the query. `ParseQuery` lets you choose whether to query the network (`fromNetwork`) or the local datastore (`fromLocalDatastore` or `fromPin(label)` to query just a subset). It is also possible to chain both requests, or execute them in parallel.
346+
347+
For instance, to query the cache first and then the network,
348+
349+
```java
350+
final ParseQuery query = ...
351+
query.fromLocalDatastore().findInBackground().continueWithTask((task) -> {
352+
// Update UI with results from Local Datastore ...
353+
// Now query the network:
354+
return query.fromNetwork().findInBackground();
355+
}, Task.UI_EXECUTOR).continueWithTask((task) -> {
356+
// Update UI with results from Network ...
357+
return task;
358+
}, Task.UI_EXECUTOR);
359+
```
360+
361+
Or you might want to query the cache, and if that fails, fire a network call:
362+
363+
```java
364+
final ParseQuery query = ...
365+
query.fromLocalDatastore().findInBackground().continueWithTask((task) -> {
366+
Exception error = task.getError();
367+
if (error instanceof ParseException && ((ParseException) error).getCode() == ParseException.CACHE_MISS) {
368+
// No results from cache. Let's query the network.
369+
return query.fromNetwork().findInBackground();
370+
}
371+
return task;
372+
}).continueWithTask((task) -> {
373+
// Update UI with results ...
374+
return task;
375+
}, Task.UI_EXECUTOR);
376+
```
377+
378+
### Without Local Datastore
344379

345380
If you aren't using the local datastore, you can use the per-query cache for `ParseQuery` instead. The default query behavior doesn't use the cache, but you can enable caching with `setCachePolicy`. For example, to try the network and then fall back to cached data if the network is not available:
346381

0 commit comments

Comments
 (0)