Firebase Sign Out

suggest change

Initialization of variable

private GoogleApiClient mGoogleApiClient;

Build the client in onCreate() of the activity that hosts the sign-out button. That activity must be a FragmentActivity and implement OnConnectionFailedListener.

mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API)
            .build();

Run this from the sign-out button. Sign out of Firebase only after Google sign-out succeeds.

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

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents