我的 Android 客户端有问题。nuxeo 上下文包含一个 Context 和一个 AndroidHttpClient
我试图尽可能地关闭,但只有方法。Shutdown () 并阻止我稍后在我的应用程序中质疑我的 nuxeo 服务器
我怎样才能关闭它?
堆叠打印
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.<init>(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.<init>(AndroidAutomationClient.java:115>)
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.<init>(NuxeoContext.java:110)
05-20 11:46:06.945: E/AndroidHttpClient(24191): at org.nuxeo.android.context.NuxeoContext.<init>(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)
代码
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();
}
NuxeoContext :
public synchronized AndroidAutomationClient getNuxeoClient() {
while (nuxeoClient != null && 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;
}
Connection.getSession :
public class Connection extends AsyncTask<NuxeoContext, Void, Session> {
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;
}
}
我将 Nuxeo 连接器集成为一个库,我不使用片段,只使用活动。