I'm creating an app and I successfully resolved logging in with Facebook using Facebook SDK 4.7.0. I'm using LoginManager (not LoginButton) as I want to have a custom button for this.
The flow is like this:
null.I implemented the following on the Logout Button onClickListener:
FacebookSdk.sdkInitialize(getApplication().getApplicationContext());
 LoginManager.getInstance().logOut();
But when I press the button on my device it doesn't do anything (shows only ViewPostImeInputStage ACTION_DOWN in logcat, which is standard for a button press.
I saw other posts on SO in which this method worked so I don't understand why it won't work in my case.
SignInActivity.java
    FacebookSdk.sdkInitialize(getApplication().getApplicationContext());
    callbackManager = CallbackManager.Factory.create();
    LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.e(TAG, "User ID: " + loginResult.getAccessToken().getUserId());
            Log.e(TAG, "Auth Token: " + loginResult.getAccessToken().getToken());
            SharedPreferences prefs = getSharedPreferences("com.dotfreeride.dotfreeride.login", 0);
            SharedPreferences.Editor editor = prefs.edit();
            editor.putString("userId", loginResult.getAccessToken().getUserId());
            editor.putString("fbToken", loginResult.getAccessToken().getToken());
            editor.commit();
        }
        @Override
        public void onCancel() {
            Toast.makeText(SignInActivity.this, "Login attempt canceled!", Toast.LENGTH_SHORT).show();
        }
        @Override
        public void onError(FacebookException error) {
            Toast.makeText(SignInActivity.this, "Login attempt failed!", Toast.LENGTH_SHORT).show();
        }
    });
MainActivity.java
logoutBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FacebookSdk.sdkInitialize(getApplication().getApplicationContext());
                LoginManager.getInstance().logOut();
            }
        });
                This worked for me
public class Profile extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_profile);
}
public void gotoLogin(View view){
    FacebookSdk.sdkInitialize(getApplicationContext());
    LoginManager.getInstance().logOut();
    Intent intent = new Intent(this, Login.class);
    startActivity(intent);
}
}
I had the same problem because i extented the AppCompatActivity. With ActionBar it works. Hope it will do the work for you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With