Skip to content

Android docs for ParsePush.setPushTime() and changes in ParseQuery #440

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion _includes/android/push-notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,21 @@ wpPush.sendPushInBackground();

## Scheduling Pushes

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.
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:

```java
long tomorrowTime = ...; // in seconds

// Send push notification with expiration interval
ParsePush push = new ParsePush();
push.setPushTime(tomorrowTime);
push.setMessage("You previously created a reminder for the game today");
push.sendPushInBackground();
```

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.

The scheduled time cannot be in the past, and can be up to two weeks in the future.

## Receiving Pushes

Expand Down
37 changes: 36 additions & 1 deletion _includes/android/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ You can query from the local datastore using exactly the same kinds of queries y

## Caching Queries

### With Local Datastore enabled

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.

```java
Expand Down Expand Up @@ -340,7 +342,40 @@ query.findInBackground(new FindCallback<ParseObject>() {
});
```

Now when you do any query with `fromLocalDatastore`, these objects will be included in the results if they still match the query.
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.

For instance, to query the cache first and then the network,

```java
final ParseQuery query = ...
query.fromLocalDatastore().findInBackground().continueWithTask((task) -> {
// Update UI with results from Local Datastore ...
// Now query the network:
return query.fromNetwork().findInBackground();
}, Task.UI_EXECUTOR).continueWithTask((task) -> {
// Update UI with results from Network ...
return task;
}, Task.UI_EXECUTOR);
```

Or you might want to query the cache, and if that fails, fire a network call:

```java
final ParseQuery query = ...
query.fromLocalDatastore().findInBackground().continueWithTask((task) -> {
Exception error = task.getError();
if (error instanceof ParseException && ((ParseException) error).getCode() == ParseException.CACHE_MISS) {
// No results from cache. Let's query the network.
return query.fromNetwork().findInBackground();
}
return task;
}).continueWithTask((task) -> {
// Update UI with results ...
return task;
}, Task.UI_EXECUTOR);
```

### Without Local Datastore

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:

Expand Down