Why is my facebook session still valid after I am

2019-07-20 02:28发布

问题:

My logout code:

if(fb.isSessionValid()){    
            masyncfb.logout(this, new RequestListener() {
                  @Override
                  public void onComplete(String response, Object state) {
                      Log.d(TAG, "Logging you out: "+response);
                  }

                  @Override
                  public void onIOException(IOException e, Object state) {}

                  @Override
                  public void onFileNotFoundException(FileNotFoundException e,
                        Object state) {}

                  @Override
                  public void onMalformedURLException(MalformedURLException e,
                        Object state) {}

                  @Override
                  public void onFacebookError(FacebookError e, Object state) {}
                });
                      updateButtonImage();                  

        }else{

and my updateButtonImage() method is:

private void updateButtonImage() {
        // TODO Auto-generated method stub
        if(fb.isSessionValid()){
            Toast.makeText(MainActivity.this, "logged in", Toast.LENGTH_LONG).show();
            button.setImageResource(R.drawable.logout);
        }else{
            button.setImageResource(R.drawable.login);
            Toast.makeText(MainActivity.this, "logged out", Toast.LENGTH_LONG).show();
        }
    }

updateButtonImage() method changes the button image from 'Log In' to 'Log Out' after login but doesn't change the button from 'Log Out' to 'Log In' after logout. I am sure that I have successfully logged out from Facebook after clicking the logout button(from logcat). so, that means my session is still valid, although I have successfully logged out from facebook. why? how can i fix the problem? all i need to change button from 'Log Out' to 'Log In'. what should i do?

N.B: i'm using facebook SDK

edited

i think i am trying to change my button before the thread in logout method in AsyncFacebookRunner.java finished its job. if it is true then, how should i wait for the thread to complete its work and then execute my updateButtonImage() method.

回答1:

To get rid of it, I use sessionlogin. With that, it is working fine.