Skip to content
This repository was archived by the owner on Sep 10, 2022. It is now read-only.
This repository was archived by the owner on Sep 10, 2022. It is now read-only.

Disconnecting ApiClient Kills ResultCallback #14

@devunwired

Description

@devunwired

In the app-indexing sample, onStop() has the following code to end the indexing action and log the result:

final String TITLE = recipe.getTitle();
final Uri APP_URI = BASE_APP_URI.buildUpon().appendPath(recipe.getId()).build();

Action viewAction = Action.newAction(Action.TYPE_VIEW, TITLE, APP_URI);
PendingResult<Status> result = AppIndex.AppIndexApi.end(mClient, viewAction);

result.setResultCallback(new ResultCallback<Status>() {
    @Override
    public void onResult(Status status) {
        if (status.isSuccess()) {
            Log.d(TAG, "App Indexing API: Recorded recipe "
                    + recipe.getTitle() + " view end successfully.");
        } else {
            Log.e(TAG, "App Indexing API: There was an error recording the recipe view."
                    + status.toString());
        }
    }
});

mClient.disconnect();

The problem with this is that immediately disconnecting from the client means the ResultCallback will never fire, making it pointless. Either the ResultCallback should be removed from this sample, or the code should wait until the result is received to disconnect, a la:

result.setResultCallback(new ResultCallback<Status>() {
    @Override
    public void onResult(Status status) {
        if (status.isSuccess()) {
            Log.d(TAG, "App Indexing API: Recorded recipe "
                    + recipe.getTitle() + " view end successfully.");
        } else {
            Log.e(TAG, "App Indexing API: There was an error recording the recipe view."
                    + status.toString());
        }

        mClient.disconnect();
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions