GoogleApiClient: “Result Already Used” in a multi-threaded Android application

what's the best approach for handling

java.lang.IllegalStateException: Result has already been consumed.
    at com.google.android.gms.common.internal.zzx.zza(Unknown Source)
    at com.google.android.gms.internal.zzly.await(Unknown Source)
    at com.google.android.gms.internal.zzmo.await(Unknown Source)
    at com.google.android.gms.internal.zzmo.get(Unknown Source)

What happens when using two different GoogleApiClients from different threads?

I have MainActivity that onStart () creates a new instance of GoogleApiClient and then calls

OptionalPendingResult<GoogleSignInResult> opr = 
    GoogleSignInApi.silentSignIn(googleApiClient);
opr.setResultCallback(myCallback);

At the same time, the activity launches the IntentService (to update the GCM token), which also creates a new instance of GoogleApiClient and calls

OptionalPendingResult<GoogleSignInResult> opr = 
    GoogleSignInApi.silentSignIn(googleApiClient);
opr.await(); // Blocks
return opr.get();

An exception occurs on a call opr.get(). It seems that GoogleApiClient is sharing its resources somewhere, and creating a new instance of this does not free me from managing some cross-flow state.

What is your approach to using GoogleApiClient when you need it twice?

ApiClient? , , " , , "? - GoogleApiClient?

UPDATE

MainActivity GoogleApiClient , .

IntentService GoogleSignInAccount OAuth. , , GoogleApiClient. , , GoogleSignInAccount - . , ?

+4
1

, opr.await() .

OptionalPendingResult<GoogleSignInResult> opr = 
    GoogleSignInApi.silentSignIn(googleApiClient);
return opr.await(); // Blocks
+1

Source: https://habr.com/ru/post/1620044/


All Articles