I implemented facebook login in my android app, and using signing in my app, but i do not know how to log out a user? after signin if i re-launch and re-signin i always see "You have already authorized AppName" and want to take the user data like email,name etc. My purpose of using facebook is authorize users to use app, take the user information,and logout. that's all. This is how i am signing in.
callbackManager = CallbackManager.Factory.create();
LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
System.out.println("Facebook Login Successful!");
System.out.println("Logged in user Details : ");
System.out.println("--------------------------");
System.out.println("User ID : " + loginResult.getAccessToken().getUserId());
System.out.println("Authentication Token : " + loginResult.getAccessToken().getToken());
Toast.makeText(RegisterOrSignIn.this, "Login Successful!", Toast.LENGTH_LONG).show();
}
@Override
public void onCancel() {
Toast.makeText(RegisterOrSignIn.this, "Login cancelled by user!", Toast.LENGTH_LONG).show();
System.out.println("Facebook Login failed!!");
}
@Override
public void onError(FacebookException e) {
Toast.makeText(RegisterOrSignIn.this, "Login unsuccessful!", Toast.LENGTH_LONG).show();
System.out.println("Facebook Login failed!!");
}
});
But it never shows any toast,(I copied this code from somewhere) and this two chunks for log out:
@Override
public void onBackPressed() {
new AlertDialog.Builder(this)
.setTitle("Really Exit?")
.setMessage("Are you sure you want to exit?")
.setNegativeButton(android.R.string.no, null)
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
LoginManager.getInstance().logOut();
RegisterOrSignIn.super.onBackPressed();
}
}).create().show();
}
I tried this so far but not getting what i want.
@Override protected void onDestroy() {
super.onDestroy();
LoginManager.getInstance().logOut();
}