问题
Excuse me for double posting this question, I did not get a response and I still have the same problem. Tried to fix it, but wasn't successful. Any help is greatly appreciated.
I want to use the Facebook login button to sign users in to my app.
Now when the loginbutton
is clicked, I log in and continue to the 2nd activity.
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton) findViewById(R.id.loginButton);
loginButton.setReadPermissions("email", "public_profile");
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "facebook:onSuccess:" + loginResult);
handleFacebookAccessToken(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(TAG, "facebook:onCancel");
// ...
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, "facebook:onError", error);
// ...
}
});
Now in the 2nd activity, I have a button Sign Out which returns me to the 1st activity, and sign out my account I signed in with. Code:
AuthUI.getInstance()
.signOut(this)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
finish();
}
});
Now, everything works fine, except for the sign out part.
It does sign out the account (I can see it in my log). But when I get back to the MainActivity, the dynamic Facebook login button still says: Sign out
while it should already say Sign in with Facebook
.
This is the Facebook button I use:
<com.facebook.login.widget.LoginButton
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:layout_marginBottom="56dp"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
I have googled this, but I could not find anything. Tried to change the sign out method to
FirebaseAuth.getInstance().signOut();
But this was without any different result.
回答1:
I had the same bad experience with that. Finally, I use the LoginManager
for Facebook authentication and did something like this:
public void logOut() {
FirebaseAuth.getInstance().signOut();
LoginManager.getInstance().logOut();
}
来源:https://stackoverflow.com/questions/40985007/android-firebase-dynamic-facebook-button