2017-05-04 34 views
1

我有一個ID列表,我打算在URL中使用,使用HttpConnection獲取一些數據。我試圖用的AsyncTask從環,但它是一個壞主意,因爲我的程序與崩潰:如何在android中運行多個HTTP連接?

java.lang.OutOfMemoryError: Failed to allocate a 124606360 byte allocation with 16777216 free bytes and 103MB until OOM 

如何使許多連接彼此正確後?

+2

這與「許多連接無關的」。你正在試圖分配一個〜120MB的堆空間塊,並且幾乎所有的時間都會失敗。 – CommonsWare

+0

請求中有多少條記錄? –

+0

'得到一些數據'什麼樣的數據?你想把它放在哪裏? – greenapps

回答

1

試法新的AsyncTask()。executeOnExecutor()

或使用VolleyOkHttp

2

你可以嘗試添加android:largeHeap="true"你在你的AndroidManifest.xml中

<application 
    android:allowBackup="true" 
    android:hardwareAccelerated="false" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:largeHeap="true" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 

或者你可以嘗試使用網絡庫,例如我們Volley,Okhttp,Retrofit等。