How to log out of Facebook on Android with Firebase?

So, I figured out how to get out of Google properly. Cool. Now, what about Facebook?

When I get an error message on Facebook, for example, an error message indicating that I already have a Firebase account with the same credentials, but a different social provider, I get the "Sign out of Facebook" button. To be more clear:

I try to log in to Facebook, then I get an error message (this is not my problem!), But the problem is that the Facebook button is now included in the "Exit". When it should still be "Login to Facebook . " I know why this is happening; this is because the error is related to Firebase and Facebook thinks I logged in.

But the real question is , how can I exit Facebook correctly? FirebaseAuth.getInstance().signout() does not seem to exit Facebook .

Here is my current logout() method:

 static void logOut(final Context context) { new SweetAlertDialog(context, SweetAlertDialog.WARNING_TYPE) .showCancelButton(true) .setTitleText(context.getString(R.string.areYouSure)) .setContentText(context.getString(R.string.logoutMSG)) .setCancelText(context.getString(android.R.string.no)) .setCancelClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(SweetAlertDialog sweetAlertDialog) { sweetAlertDialog.dismiss(); } }) .setConfirmText(context.getString(R.string.yes)) .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() { @Override public void onClick(final SweetAlertDialog sweetAlertDialog) { //region Google GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken(context.getString(R.string.default_web_client_id)) .requestEmail() .build(); final GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(context) .enableAutoManage((FragmentActivity) context, new GoogleApiClient.OnConnectionFailedListener() { @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { FirebaseCrash.log(connectionResult.getErrorMessage()); Toast.makeText(context, context.getString(R.string.error), Toast.LENGTH_SHORT).show(); } }) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); mGoogleApiClient.registerConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {@ Override public void onConnected(@Nullable Bundle bundle) { FirebaseAuth.getInstance().signOut(); if (mGoogleApiClient.isConnected()) { Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new ResultCallback < Status > () {@ Override public void onResult(@NonNull Status status) { if (status.isSuccess()) { FirebaseAuth.getInstance().signOut(); sweetAlertDialog.dismiss(); Log.d(TAG, "User Logged out"); Intent intent = new Intent(context, SignUp.class); context.startActivity(intent); ((FragmentActivity) context).finish(); } else Toast.makeText(context, context.getString(R.string.error), Toast.LENGTH_SHORT).show(); } }); } } @ Override public void onConnectionSuspended(int i) { Log.e(TAG, "Google API Client Connection Suspended"); } }); //endregion } }).show(); } 
+6
source share
1 answer

I had a similar problem and it was solved using an Auth Firebase instance and facebook LoginManager

 FirebaseAuth.getInstance().signOut(); LoginManager.getInstance().logOut(); 

My question

+23
source

All Articles