patloew / RxLocation

🗺 [DEPRECATED] Reactive Location APIs Library for Android and RxJava 2

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GoogleAPIClientSingle example

josh-burton opened this issue · comments

Can you provide an example of how to use GoogleAPIClientSingle?

It seems if I subscribe to this single, and flatMap to another observable where I can use the client, the client is disconnected before the chain completes.

Could you please provide the whole chain where the problem occurs? I'll look into it then.

I'm attempting to use it like this:

    GoogleAPIClientSingle.create(context, Auth.CREDENTIALS_API)
        .flatMap(client -> Single.create(new SingleOnSubscribe<CredentialRequestResult>() {
            @Override
            public void subscribe(SingleEmitter<CredentialRequestResult> emitter) throws Exception {
                 CredentialRequest credentialRequest = new CredentialRequest.Builder()
                         .setPasswordLoginSupported(true)
                         .build();

                 Auth.CredentialsApi.request(client, credentialRequest).setResultCallback(new ResultCallback<CredentialRequestResult>() {
                     @Override
                     public void onResult(@NonNull CredentialRequestResult result) {
                         emitter.onSuccess(result);
                     }
                 });

             }
     }));

The problem was that Single immediately unsubscribes when onSuccess() is called. I refactored it to GoogleApiClientFlowable, which should work now.