2

私の古いデバイスである LG Optimus 3d (Android 2.2) ではなく、Nexus 7 (4.3) で HttpPost を実行すると、次のようになります。

E/InputDispatcher﹕ チャネル '4273f7b0 ... MainActivity (server)' ~ チャネルは回復不能なほど壊れており、破棄されます!

人々はメモリリークの可能性について言及しています。見る **。ただし、この問題は、HttpPost を試すと、起動時にすぐに発生します。それでもメモリリークの可能性はありますか?

これが私がHttpPostをやっている方法です:

public void server_addUserGetId()
{
    String url = GS.baseUrl() + "/users";
    HttpPost theHttpPost = new HttpPost(url);

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("dId", s_UserInfo.getInstance().m_device_id ));
    try {
        theHttpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    HttpPostAsync theHttpPostAsync = new HttpPostAsync(new OnPostExecuteHandler() {
        @Override
        public void handlePostExecute(Object oHttpResponse) {
            HttpResponse theHttpResponse = (HttpResponse) oHttpResponse;
            JSONObject jo = GS.getJSONObject(theHttpResponse.getEntity());
            try {
                s_UserInfo.getInstance().m_user_id = jo.getString("_id");
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
    theHttpPostAsync.execute(theHttpPost);
    return;
}

ここに私の HttpPostAsync タスクがあります:

public class HttpPostAsync extends AsyncTask<HttpPost, Integer, HttpResponse>
{
    private HttpPost m_HttpPost;
    private HttpResponse m_HttpResponse;

    private OnPostExecuteHandler m_OnPostExecuteHandler;
    public HttpPostAsync(OnPostExecuteHandler listener)
    {
        m_OnPostExecuteHandler = listener;
    }

    protected HttpResponse doInBackground(HttpPost ... args)
    {
        m_HttpPost = args[0];
        if(GS.dl>5) Log.d("GRA: HttpPostAsync", "doInBackground: Thread.currentThread().getId()=" + Thread.currentThread().getId());
        m_HttpResponse = visit(m_HttpPost);
        return m_HttpResponse;
    }

    protected void onProgressUpdate(Integer... progress) {
    }

    protected void onPostExecute(Long result) {
        if(GS.dl>5) Log.d("GRA: HttpPostAsync", "onPostExecute: Thread.currentThread().getId()=" + Thread.currentThread().getId());
        if(GS.dl>5) Log.d("GRA: HttpPostAsync", "onPostExecute: result=" + result);
        //if(GS.dl>5) Log.d("GRA: HttpPostAsync", "onPostExecute: m_HttpEntity="+m_HttpEntity);
        m_OnPostExecuteHandler.handlePostExecute(m_HttpResponse);
    }

    public HttpResponse visit(HttpPost theHttpPost)
    {
        HttpResponse response = null;
        try {
            // Create a new HttpClient and Post Header
            HttpClient httpclient = new DefaultHttpClient();
            // Execute HTTP Post Request
            response = httpclient.execute(theHttpPost);
        } catch (IOException e) {
            e.printStackTrace();
            Log.d("HttpPostAsync.java", "IOException e=" + e);
            // TODO Auto-generated catch block
        }
        return response;
    }
}

何か案は?

SO answer* を読んだので、ArrayList の初期化に関係している可能性があるため、ArrayList で 1 を使用してこのように初期化しようとしましたが、問題は解決しません。

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);

*: 完全に関連/助けにならなかった SO の回答: アプリは Android の動作を停止しました

**メモリリーク関連?http://android-developers.blogspot.com/2011/03/memory-analysis-for-android.html

4

2 に答える 2