So I need to implement facebook logout function in my android application. The thing is that most of the answers suggests to use LoginManager.Instance.LogOut();
but this method logs out from facebook in all devices that you were logged in. In my case I need only log out from my application and then when logout was successful I need to navigate back to login screen. So I thought about using the same approach as logging in.
This is my facebook login View:
class FacebookLoginView : MvxActivity, IFacebookCallback
{
private LoginButton loginButton;
private ICallbackManager callbackManager;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
RequestWindowFeature(WindowFeatures.NoTitle);
SetContentView(Resource.Layout.FacebookLoginView);
var loaderService = Mvx.Resolve<IMvxViewModelLoader>();
ViewModel = (FacebookLoginViewModel)loaderService.LoadViewModel(new MvxViewModelRequest(typeof(FacebookLoginViewModel)), null);
loginButton = FindViewById<LoginButton>(Resource.Id.loginButton1);
loginButton.SetReadPermissions(new string[] { "user_friends", "email" });
callbackManager = CallbackManagerFactory.Create();
loginButton.RegisterCallback(callbackManager, this);
}
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
callbackManager.OnActivityResult(requestCode, (int)resultCode, data);
}
public void OnCancel()
{
//Does nothing, just closes facebook login screen
}
public void OnError(FacebookException error)
{
//For now does nothing
}
public async void OnSuccess(Java.Lang.Object result)
{
var loginResult = result as LoginResult;
await ((FacebookLoginViewModel)ViewModel).GetAccountInfoAndSaveAsync(loginResult.AccessToken.Token);
}
}
So I want the logout to be the same way as login... When I click logout button popup appears to ask if I'm sure and after I press "OK" button I want to jump to some callback like OnSuccess
and then navigate to login screen. When I try to implement this, nothing happens... It just logs out and stays in the same view... I tried debugging and saw that it does not stop in any of OnCancel
, OnError
or OnSuccess
methods, so could anyone help me to do this logout?