title: Facebook android SDK reopens session
body: <p>I am developing a facebook-integrated application and i am experiencing a very weird issue.</p>
  
  <p>I log in normally, but as i am about to log out the SDK forces a login again...</p>
  
  <pre><code>package com.machinarius.facebook;
  
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.LinkedList;
  import java.util.List;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  import com.facebook.Request;
  import com.facebook.Request.GraphUserCallback;
  import com.facebook.Response;
  import com.facebook.Session;
  import com.facebook.Session.NewPermissionsRequest;
  import com.facebook.Session.StatusCallback;
  import com.facebook.SessionState;
  import com.facebook.model.GraphUser;
  
  public class MainActivity extends Activity implements StatusCallback, GraphUserCallback {
      private TextView statusText;
      private Button loginButton;
      private Boolean loggedIn;
      private Session actualSession;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          loggedIn = false;
          statusText = (TextView)findViewById(R.id.statusText);
          loginButton = (Button)findViewById(R.id.loginButton);
      }
  
      @Override
      public void onActivityResult(int requestCode, int resultCode, Intent data) {
          super.onActivityResult(requestCode, resultCode, data);
          Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
      }
  
      public void toggleFacebookLogin(View source) {
          if(!loggedIn) {
              actualSession = Session.openActiveSession(this, true, this);
          }
          else 
              if(actualSession == null)
                  return;
              else {
                  actualSession.close();
                  statusText.setText("Please login");
                  loggedIn = false;
              }
      }
  
      @Override
      public void call(Session session, SessionState state, Exception exception) {
          if(state.equals(SessionState.OPENED)) {
              loggedIn = true;
              List&lt;String&gt; permissions = getNewPermissions(actualSession.getPermissions(), 
                      new LinkedList&lt;String&gt;(Arrays.asList("user_about_me", "user_birthday", "user_hometown", "user_relationships", "user_location", "user_relationships", "email")));
              Session.NewPermissionsRequest permissionsRequest = new NewPermissionsRequest(this, permissions);
              actualSession.requestNewReadPermissions(permissionsRequest);
              populateInterface();
          } else {
              loggedIn = false;
          }
      }
  
      private void populateInterface() {
          Request.executeMeRequestAsync(Session.getActiveSession(), this);
      }
  
      @Override
      public void onCompleted(GraphUser user, Response response) {
          if(response.getError() != null) {
              statusText.setText("There was an error fetching your info");
              Log.e(getClass().getName(), response.getError().toString());
              return;
          }
          if(user != null) {
              statusText.setText("Hello " + user.getName() + "\n"
                      + "Your user ID is " + user.getId() + "\n"
                      + "Your birthday is " + user.getBirthday());
              loginButton.setText("Log out");
          } else {
              statusText.setText("There was an error fetching your info");
          }
      }
  
      private List&lt;String&gt; getNewPermissions(List&lt;String&gt; actualPermissions, List&lt;String&gt; desiredPermissions) {
          ArrayList&lt;String&gt; permissionsGranted = new ArrayList&lt;String&gt;();
          for(String nPermission : desiredPermissions)
              for(String aPermission : actualPermissions)
                  if(nPermission.equals(aPermission))
                      permissionsGranted.add(nPermission);
          for(String gPermission : permissionsGranted)
              desiredPermissions.remove(gPermission);
          return desiredPermissions;
      }
  }
  </code></pre>
  
  <p>toggleFacebookLogin is called by a XML onClick handler on the loginButton.</p>
  
  <p>Another question as well, how can i integrate the permissions request into the session.open call so i dont have to make the user see a facebook dialog twice?</p>