store context in shared preference for facebook logout in Android

694 Views Asked by At

i develop a game project in which i have implemented facebook sdk for posting scores on the wall in facebook. But there is a problem for logout in facebook. I have to logout from facebook in settings page which is different page from where i have to login in facebook. In facebook SDK there is a function logout which requires the context from which i have logged in. I have to store context in shared preference for this. How can i do that?

1

There are 1 best solutions below

1
On

I have done Same thing in my Code Like This... In your Activity Where you have Created object of Facebook make it public static like

public static Facebook mFacebook

and in activity where you want to logout From Facebook use Following Function

private void LogoutFacebook()
{
    if(FacebookLoginActivity.mFacebook != null)
    {

        if (FacebookLoginActivity.mFacebook.isSessionValid()) 
        {
            AsyncFacebookRunner asyncRunner = new   AsyncFacebookRunner(FacebookLoginActivity.mFacebook);
            asyncRunner.logout(AdvanceSetting.this, new LogoutRequestListener());
        }
    }
}

also add this class where you want to Logout

 private class LogoutRequestListener extends BaseRequestListener 
    {
        public void onComplete(String response) 
        {

                    SessionEvents.onLogoutFinish();

        }
    }

Hope it may useful to you..