title: AndroidHttpClient create and never close
body: <p>I have a problem with my Android client.
  The nuxeo context contains a Context and a AndroidHttpClient </p>
  
  <p>I tried to close by all the way possible but there are only the method. Shutdown () and it prevents me to question my nuxeo server later in my app</p>
  
  <p>How can I close it ?</p>
  
  <p>Stack print</p>
  
  <pre><code>05-20 11:46:06.945: E/AndroidHttpClient(24191): Leak found
  05-20 11:46:06.945: E/AndroidHttpClient(24191): java.lang.IllegalStateException: AndroidHttpClient created and never closed
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.net.http.AndroidHttpClient.&lt;init&gt;(AndroidHttpClient.java:158)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.net.http.AndroidHttpClient.newInstance(AndroidHttpClient.java:144)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at org.nuxeo.ecm.automation.client.android.AndroidAutomationClient.&lt;init&gt;(AndroidAutomationClient.java:115&gt;)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at org.nuxeo.android.context.NuxeoContext.getNuxeoClient(NuxeoContext.java:168)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at org.nuxeo.android.context.NuxeoContext.&lt;init&gt;(NuxeoContext.java:110)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at org.nuxeo.android.context.NuxeoContext.&lt;init&gt;(NuxeoContext.java:82)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at com.example.androidnuxeo.MainActivity.onCreate(MainActivity.java:90)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.app.Activity.performCreate(Activity.java:4562)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.app.ActivityThread.access$600(ActivityThread.java:128)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.os.Handler.dispatchMessage(Handler.java:99)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.os.Looper.loop(Looper.java:137)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at android.app.ActivityThread.main(ActivityThread.java:4514)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at java.lang.reflect.Method.invokeNative(Native Method)
  05-20 11:46:06.945: E/AndroidHttpClient(24191): at java.lang.reflect.Method.invoke(Method.java:511)
  </code></pre>
  
  <p>Code </p>
  
  <pre><code> NuxeoContext ctx = new NuxeoContext(getBaseApplication());
  
  try {
  
      Session session = Connection.getSession();
  
      itemID = ((TwoLineListItem) view).getText2().getText().toString();
      itemTitle =((TwoLineListItem) view).getText1().getText().toString();
  
      RequeteDetail requete = new RequeteDetail();
      res = requete.execute(itemID,ctx).get();
      type = res.getType();
  
  } catch (Exception e) {
      System.err.println(e);
      e.printStackTrace();
  }
  </code></pre>
  
  <p>NuxeoContext :</p>
  
  <pre><code>public synchronized AndroidAutomationClient getNuxeoClient() {
      while (nuxeoClient != null &amp;&amp; shuttingDown) {
          try {
              wait(100);
          } catch (InterruptedException e) {
              // Do nothing
          }
      }
      if (nuxeoClient == null || nuxeoClient.isShutdown()) {
          shuttingDown = false;
         nuxeoClient = new AndroidAutomationClient(
                 serverConfig.getAutomationUrl(), androidContext,
                  sqlStateManager, blobStore, networkStatus, serverConfig);
          Log.i(TAG, "new Nuxeo client " + nuxeoClient);
          if (Log.isLoggable(TAG, Log.DEBUG)) {
              Log.d(TAG, "Call stack: ", new Exception());
          }
      }
      return nuxeoClient;
  }
  </code></pre>
  
  <p>Connection.getSession :    </p>
  
  <pre><code>public class Connection extends AsyncTask&lt;NuxeoContext, Void, Session&gt; {
  
  Context ctx;
  static Session session;
  
  protected Session doInBackground(NuxeoContext... params) {
  
      if(session == null || session.getClient().getBaseUrl() == null) {
          NuxeoContext nctx= params[0];
          session = nctx.getSession();    
  
          System.err.println("create connexion");
      }
      else {
          System.err.println("connexion already open");
      }
  
     return session;
  }
  
  public static Session getSession() {
      if(session == null || session.getClient() == null) {
          System.err.println("No connexion");
      }
      return session;
  }
  }
  </code></pre>
  
  <p>I integrated the Nuxeo connector as a library and I don't use the fragment, only activities.</p>