只有在此过程中创建新的全新Google用户时才会发生这种情况 它适用于现有的Google用户。
我的SignInRegisterActivity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GoogleSignInOptions.Builder gsoBuilder = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN);
GoogleSignInOptions gso = gsoBuilder.requestEmail()
.requestServerAuthCode(BuildConfig.GOOGLE_SIGNIN_WEB_ID)
.requestScopes(new Scope(Scopes.PROFILE), new Scope(Scopes.EMAIL), new Scope("https://www.googleapis" +
".com/auth/user.birthday.read"))
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(@Nullable Bundle bundle) {
Logger.i("onConnected");
}
@Override
public void onConnectionSuspended(int i) {
Logger.i("onConnectionSuspended %d", i);
}
})
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
...
private void logout() {
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
Logger.i("onResult - %d - %s", status.getStatusCode(), status.getStatusMessage());
}
});
}
流程:
startActivityForResult
logout()
函数为什么呢? GoogleApiClient应该已经在步骤6中连接了。因为我在SignInRegisterActivity的onCreate()
中调用了它。
是因为在活动的onStop()
中隐式调用了GoogleApiClient的断开连接吗?
E / PRETTY_LOGGER:│Activity.dispatchActivityResult (Activity.java:7137)E / PRETTY_LOGGER:│
SignInRegisterActivity.onActivityResult (SignInRegisterActivity.java:239)E / PRETTY_LOGGER: ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ ┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄ ┄┄┄┄┄┄┄┄┄┄┄┄┄ E / PRETTY_LOGGER:│:java.lang.IllegalStateException:GoogleApiClient 尚未连接。 E / PRETTY_LOGGER:│在 com.google.android.gms.internal.zzaas.zzb(未知来源) E / PRETTY_LOGGER:│在 com.google.android.gms.internal.zzaav.zzb(未知来源) E / PRETTY_LOGGER:│在 com.google.android.gms.internal.zzaat.zzb(未知来源) E / PRETTY_LOGGER:│在 com.google.android.gms.auth.api.signin.internal.zze.zza(未知 来源)E / PRETTY_LOGGER:│在 com.google.android.gms.auth.api.signin.internal.zzc.signOut(未知 来源)E / PRETTY_LOGGER:│在 com.sephora.digital.views.activities.SignInRegisterActivity.logout(SignInRegisterActivity.java:253) E / PRETTY_LOGGER:│在 com.sephora.digital.views.activities.SignInRegisterActivity.onActivityResult(SignInRegisterActivity.java:239) E / PRETTY_LOGGER:│在 android.app.Activity.dispatchActivityResult(Activity.java:7137) E / PRETTY_LOGGER:│在 android.app.ActivityThread.deliverResults(ActivityThread.java:4916) E / PRETTY_LOGGER:│在 android.app.ActivityThread.handleSendResult(ActivityThread.java:4963) E / PRETTY_LOGGER:│在 android.app.ActivityThread.access $ 1600(ActivityThread.java:221) E / PRETTY_LOGGER:│在 android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1848) E / PRETTY_LOGGER:│在 android.os.Handler.dispatchMessage(Handler.java:102)E / PRETTY_LOGGER: │在android.os.Looper.loop(Looper.java:158)E / PRETTY_LOGGER:│at android.app.ActivityThread.main(ActivityThread.java:7224) E / PRETTY_LOGGER:│在java.lang.reflect.Method.invoke(本机方法) E / PRETTY_LOGGER:│在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1230) E / PRETTY_LOGGER:│在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)