Loslassen-Verbindung in android

Habe ich nur einen httpclient in meiner 1. Aktivität, die in alle anderen Aktivitäten.Weil ich bin mit PHP-Sessions.

In meiner 1. Aktivität ich habe eine listview, die dauert 4-5 Sekunden zu laden, Elemente
(was wird getan werden, indem eine Verbindung zu dem server), und in der gleichen Tätigkeit habe ich ein such-Feld...auf die Schaltfläche klicken, dauert mir zu einem searchActivity, wo mit der gleichen httpclient suchen Sie Ergebnisse werden geladen in ein anderes listview.
Mein problem ist, während der 4-5 Sek Ladezeit in der 1. Aktivität, wenn ich versuche zu suchen, etwas, das meine app abstürzt sagt:

Ungültige Verwendung von SingleClientConnManager: Verbindung noch Mittel.

Stellen Sie sicher, um die Verbindung zu lösen, bevor die Zuweisung einer anderen.

java.lang.IllegalStateException: No gewickelt Verbindung.

und schließlich eine null-Zeiger-Ausnahme später

Ich denke, als bin ich mit dem gleichen httpclient in der searchActivity vor Abschluss der 1. Aktivität ist das erstellen dieser Fehler (korrigiert mich, wenn falsch) bin

also, wenn meine Vermutung richtig ist, wie kann ich loslassen diese Verbindung in der Absicht, wo ich in Bewegung bin, searchAvtivity vom 1. Aktivität??

Danke

CODE:

    try {
        HttpPost httppost = new HttpPost(
                SignUpActivity.url+"/feed/fetchfeed");
        httppost.setHeader("X_REQUESTED_WITH", "xmlhttprequest");
        httppost.setHeader("MOBILE_DATA_REQUESTED", "mobileHttpRequest");
        HttpResponse response = SignUpActivity.httpclient.execute(httppost);

        Log.d("response", "" + response);
        HttpEntity entity = response.getEntity();

        Log.d("entity", "" + entity);
        is = entity.getContent();

        Log.d("is", "" + is);

        try {
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(is, "iso-8859-1"), 8);
            sb = new StringBuilder();
            sb.append(reader.readLine() + "\n");

            Log.d("sb", "" + sb);
            String line = "0";
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            result = sb.toString();
            Log.d("result", result);
        } catch (Exception e) {
            Log.e("error3", "Error in http connection" + e.toString());
        }

        Log.e("response", "response is:" + response.toString());
    } catch (Exception e) {
        Log.e("error4", "Error in http connection" + e.toString());
    }

    try {
        Log.d("JArray", "entered try");
        JArray = new JSONArray(result);
        feed_products_list = new ArrayList<Product>();
        Log.d("JArray", "try last line");
    } catch (JSONException e) {
        Log.d("JArray", "in catch");
        e.printStackTrace();
    }

    JSONObject jsonObj;
    JSONObject jsonObjStore;
    JSONObject jsonObjUser;

    for (int i = 0; i < JArray.length(); i++) {
        try {
            Log.d("jsonObj",
                    "entered try" + " " + i + " " + JArray.length());
            jsonObj = JArray.getJSONObject(i);
            jsonObjUser = jsonObj.getJSONObject("user");
        } catch (Exception e) {
            Log.d("jsonObj", "in catch");
            continue;
        }

        try {
            Log.d("feed_products_list", "entered try");
            Log.d("type of action", jsonObj.getString("action"));
            if (jsonObj.getString("action").equals("entry")) {
                Log.d("if block", "entered block 'entry'");

                jsonObjStore = jsonObj.getJSONObject("store");
                Log.d("store", jsonObjStore.getString("name"));

                feed_products_list.add(new Product(jsonObj.getInt("id"),
                        jsonObj.getString("action"), jsonObj
                                .getString("image"), jsonObj
                                .getString("product_name"), jsonObj
                                .getString("reported_price_formated"),
                        jsonObjStore.getString("name"), jsonObjStore
                                .getString("area"), jsonObjStore
                                .getString("city"), jsonObj
                                .getString("mrp"), jsonObjUser
                                .getString("name"), jsonObj
                                .getLong("reported_timestamp"), jsonObj
                                .getInt("discount"), jsonObjStore
                                .getDouble("lat"), jsonObjStore
                                .getDouble("lng")));

                Log.d("store id", jsonObjStore.getString("id"));
                Log.d("feed_products_list product: ",
                        feed_products_list.get(i).lat + "   "
                                + feed_products_list.get(i).lng);

            } else if (jsonObj.getString("action").equals("contest")) {
                Log.d("if block", "entered block 'contest'");
                feed_products_list.add(new Product(jsonObj.getInt("id"),
                        jsonObj.getString("action"), jsonObjUser
                                .getString("image"), jsonObj
                                .getString("product_name"), jsonObj
                                .getString("city"), jsonObjUser
                                .getString("name"), jsonObj
                                .getLong("reported_timestamp")));

                Log.d("feed_products_list",
                        feed_products_list.get(i).productName);

            }

        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    m = 1;
}

Fügte ich hinzu:

                try {
                    is.close();
            Intent intent = new Intent(FeedListViewActivity.this,
                            SearchActivity.class);
                    startActivity(intent);
                    Log.d("onClick", search_string);
                } catch (IOException e) {
                    //TODO Auto-generated catch block
                    e.printStackTrace();
                }

aber ich habe den gleichen Fehler

InformationsquelleAutor Housefly | 2012-05-29

Schreibe einen Kommentar