-1
我寫了一個web服務,它返回byte array
。java.lang.OutOfMemoryError Android SOAP響應字節數組
當我打電話從Android應用程序的服務,它給了我內存不足的錯誤就行了:
androidHttpTransport.call(SOAP_ACTION + WebMethodName, envelope);
在它工作的一些移動設備,但在某些移動設備(可能是設備具有低RAM)它會拋出內存錯誤。
請建議。
更新#2 @Rohit - 這裏是我的代碼
public static void DownloadFile(String WebMethodName, String ServiceURL)
{
byte[] imgBytes=null;
SoapObject request = new SoapObject(NAMESPACE, WebMethodName);
PropertyInfo NameProperty = new PropertyInfo();
NameProperty.setName("Name");
NameProperty.setValue("TEST");
NameProperty.setType(String.class);
request.addProperty(NameProperty);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(ServiceURL,100000);
try {
//On below line I get OOM error
androidHttpTransport.call(SOAP_ACTION + WebMethodName, envelope);
final SoapPrimitive primitive = (SoapPrimitive) envelope.getResponse();
if (primitive == null)
{
imgBytes=null;
}
else
{
final String imgData = primitive.toString();
if (imgData != "")
{
imgBytes = Base64.decode(imgData, Base64.DEFAULT);
String s = new String(imgBytes);
String filePath = android.os.Environment.getExternalStorageDirectory() +"/TestDirectory/Test.apk" ;
File file = new File(filePath);
file.getParentFile().mkdirs();
file.createNewFile();
BufferedOutputStream objectOut = new BufferedOutputStream(new FileOutputStream(file));
objectOut.write(imgBytes);
objectOut.close();
}
}
else
{
Log.w("ImgData", "Image data is null");
}
}
} catch (Exception e) {
e.printStackTrace();
Log.w("ImgData", "Error :" + e.getMessage());
}
}
更新#3
@parik dhakan
我試圖largeHeap = 「真」,但得到了同樣的錯誤。另外我讀過,不建議使用largeHeap =「true」。 感謝您的回覆。
請提供您的代碼來檢查的準確issuse。 – Rohit
@Rohit - 我在我的問題中添加了代碼。請檢查並恢復。 – Vito