1

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?

Nikas Žalias
  • 1,594
  • 1
  • 23
  • 51
  • This may help you: https://stackoverflow.com/questions/29305232/facebook-sdk-4-for-android-how-to-log-out-programmatically – Kirti Zare Sep 28 '17 at 10:00
  • @KirtiZare nope, it does not help, me.. I already mentioned `LoginManager.Instance.LogOut()` in my question – Nikas Žalias Sep 28 '17 at 10:03
  • Please read the article carefully. It is written : don't forget to put FacebookSdk.sdkInitialize(getApplicationContext()); – Kirti Zare Sep 28 '17 at 10:05
  • add this line first: FacebookSdk.sdkInitialize(this.getApplicationContext()); LoginManager.getInstance().logOut(); – Kirti Zare Sep 28 '17 at 10:05
  • @KirtiZare Please read my question carefully... I want the alternative of `LoginManager.Instance.Logout()` – Nikas Žalias Sep 28 '17 at 10:07

0 Answers0