【问题标题】:OutOfMemoryError when try to receive large json response : Android尝试接收大型 json 响应时出现 OutOfMemoryError:Android
【发布时间】:2016-02-26 09:30:08
【问题描述】:

当我尝试将 json 响应转换为字符串时,我遇到了 OutofMemoryError 异常

这是我试过的代码

 HttpEntity entity = response.getEntity();
 if(entity != null) {
    contentAsString = EntityUtils.toString(entity); // error
 }

我也尝试过使用 volley 和 Retrofit Network 库,但遇到了同样的问题。请建议...

【问题讨论】:

  • 你在模拟器或设备上试过了吗?
  • 尝试将android:largeHeap="true" 添加到清单中?
  • 你收到base64编码的图片了吗?
  • 您可以控制您的后端吗?你的 json 响应有多大?

标签: android json jackson out-of-memory android-volley


【解决方案1】:

试试这个

在您的 AndroidManifest.xml 中设置 largeHeap="true"

  <application
        android:icon="@drawable/app_icon"
        android:largeHeap="true"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

让我知道这是否适合您! :)

【讨论】:

    【解决方案2】:

    将此添加到您的清单中

    android:largeHeap="true"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-15
      • 2014-09-06
      • 1970-01-01
      • 2018-03-22
      • 2016-12-23
      • 2021-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多