java.lang.OutOfMemoryError: Failed to allocate a allocation until OOM

后端 未结 4 636
有刺的猬
有刺的猬 2021-01-15 15:37

Actually, I am trying to create a app with n number of multimedia files which includes images and videos. My apps size is around 34MB, and my assets size is aro

相关标签:
4条回答
  • 2021-01-15 16:05

    It's a common error when you dealing with Bitmap so add this line in AndroidManifest.xml: android:largeHeap="true"

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

    Hope it will be helpful.

    0 讨论(0)
  • 2021-01-15 16:08

    Simple Solution which I found is, Add hardwareAccelerated & largeHeap under application 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">
    
    0 讨论(0)
  • 2021-01-15 16:19

    This is happening because of large size image. Try with small size image i.e. of your phone screen resolution.

    I had the same problem. Tried reducing the image size in Paint with 2100 x 1300 px and it worked but the app was lagging very much.

    0 讨论(0)
  • 2021-01-15 16:22

    It sounds like you are either caching too many files in RAM or instantiating the same bitmaps and videos over and over until you run out of memory.

    You should not write your own image loading and caching code on Android in 2016 unless you have unusual requirements. Use one of the libraries that have solved this problem. See Picasso v/s Imageloader v/s Fresco vs Glide for more guidance.

    0 讨论(0)
提交回复
热议问题