title: Check if the user is Facebook logged in or not in android
body: <p>I have Developed an application that have facebook login functionality for the Login in Application so i implement Two Button in Main Page of app so when click on login with facebook its open facebook login page so my question is when user already login with fb then the button of login should be invisible so i ckeck 
  facebook.isSessionValid() is true or false but its getting false everytime</p>
  
  <p>my code</p>
  
  <pre><code>        String APP_ID = "**************";
      fb = new Facebook(APP_ID);
      login = (Button) findViewById(R.id.btnFbLogin);
  
  
      if(fb.isSessionValid())
      {
          login.setVisibility(View.GONE);
      }
  
      Toast.makeText(this, "" + fb.isSessionValid(), Toast.LENGTH_LONG).show();
  
      withoutLogin = (Button) findViewById(R.id.btnWithoutLogin);
      login.setOnClickListener(this);
      withoutLogin.setOnClickListener(this);
  }
  
  
  @Override
  public void onClick(View click) {
  
      if (click == login) {
          loginTofacebook();
  
      } else {
          Intent intent = new Intent(this, MockTest.class);
          startActivity(intent);
          Toast.makeText(this, withoutLogin.getText().toString(), Toast.LENGTH_SHORT).show();
      }
  }
  
  public void loginTofacebook() {
      mPrefs = getPreferences(MODE_PRIVATE);
      String access_token = mPrefs.getString("access_token", null);
      long expires = mPrefs.getLong("access_expires", 0);
      if (access_token != null) {
          fb.setAccessToken(access_token);
          Log.d("FB Sessions", "" + fb.isSessionValid());
      }
      if (expires != 0) {
          fb.setAccessExpires(expires);
      }
  
      {
          fb.authorize(this, new String[]{"email", "user_address ", "user_mobile_phone", "publish_stream", "manage_friendlists", "user_checkins", "friends_checkins", "read_friendlists", "manage_friendlists", "friends_birthday"}, new Facebook.DialogListener() {
  
              @Override
              public void onFacebookError(FacebookError e) {
  
                  Toast.makeText(MainActivity.this, "fbError", Toast.LENGTH_SHORT).show();
              }
  
              @Override
              public void onError(DialogError e) {
  
                  Toast.makeText(MainActivity.this, "onError", Toast.LENGTH_SHORT).show();
              }
  
              @Override
              public void onComplete(Bundle values) {
  
                  SharedPreferences.Editor editor = mPrefs.edit();
                  editor.putString("access_token", fb.getAccessToken());
                  editor.putLong("access_expires", fb.getAccessExpires());
                  editor.commit();
  
                  Intent intent = new Intent(MainActivity.this, Preparation.class);
                  startActivity(intent);
  
              }
  
              @Override
              public void onCancel() {
                  Toast.makeText(MainActivity.this, "onCancel", Toast.LENGTH_SHORT).show();
              }
          });
      }
  }
  </code></pre>
  
  <p>}</p>