从Firebase Google帐户执行退出操作

时间:2017-03-16 22:05:55

标签: android firebase firebase-authentication

我做了this问题&配置退出这样的事件:

public static void SignOut() {
    // Google sign out
    Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess())
                        Log.wtf("success", "signed out");
                    if (status.isInterrupted())
                        Log.wtf("interrupted", "not signed out");
                    if (status.isCanceled())
                        Log.wtf("cancelled", "sign out cancelled");
                }
            });
}

但是,调用SignOut()时会抛出以下错误:

  

java.lang.IllegalStateException:GoogleApiClient尚未连接。                                                                                      在com.google.android.gms.internal.zzaas.zzb(未知来源)                                                                                      在com.google.android.gms.internal.zzaav.zzb(未知来源)                                                                                      在com.google.android.gms.internal.zzaat.zzb(未知来源)                                                                                      在com.google.android.gms.auth.api.signin.internal.zze.zza(未知来源)                                                                                      在com.google.android.gms.auth.api.signin.internal.zzc.signOut(未知来源)

SignOut()之前,mAuth.signOut()被调用。

我该如何解决这个问题?

感谢。

1 个答案:

答案 0 :(得分:0)

在谷歌帐户成功完成此注销后,只需将此代码面临同样的问题。

Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
    new ResultCallback<Status>() {
        @Override
        public void onResult(Status status) {
            FirebaseAuth.getInstance().signOut();
            Intent i1 = new Intent(MainActivity.this, GoogleSignInActivity.class);
            startActivity(i1);
            Toast.makeText(MainActivity.this, "Logout Successfully!", Toast.LENGTH_SHORT).show();
        }
    });