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

Disconnecting ApiClient Kills ResultCallback #14

Open
devunwired opened this issue Jul 8, 2015 · 0 comments
Open

Disconnecting ApiClient Kills ResultCallback #14

devunwired opened this issue Jul 8, 2015 · 0 comments

Comments

@devunwired
Copy link
Contributor

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();
    }
});
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant