2

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.

Shoshi
  • 2,254
  • 1
  • 29
  • 43
  • Can you try doing `Log.d(TAG, response)` in the onComplete method of your logout just to verify that your logout was successful? – Jesse Chen Nov 29 '12 at 23:46
  • yes, i have check that all time. and it's returning 'true' all the time. @Jesse Chen – Shoshi Nov 30 '12 at 00:40
  • You should put updateButtonImage() in your onComplete method. – Ming Li Dec 03 '12 at 21:34
  • Hi @Shoshi , I am having same problem , Can you please suggest me how to solved it ? I have posted same on stack overflow also , you can check it [here](http://stackoverflow.com/questions/25376507/how-my-app-can-know-when-user-logout-from-its-native-facebook-app) – Kunu Aug 19 '14 at 10:32

1 Answers1

0

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

Mxyk
  • 10,678
  • 16
  • 57
  • 76
Shoshi
  • 2,254
  • 1
  • 29
  • 43