OutOfMemoryError. happen on phone when using image

2019-08-23 03:50发布

问题:

i have asked a lot question here about my application. i have application on google play (js - design fashion & pattern maker). i run the application on a lot devices and none of them do error. but i have some phone that does error, the phone are run android 7.1 and they galaxy s7(not just galaxy phones).

my app use a lot of images (almost 900), and i test it a lot, what can cause the OutOfMemoryRrror, it is not big image(on some phone it is work, and even on a same phone, it can work on one, but do the error on the other.). i use in manifest this 2:

android:hardwareAccelerated="false" android:largeHeap="true"

but still it don't work. the problem happen when the user add images to the main layout.

in the play console i see this:

so if i understand, after users install the app it take another 50MB in runtime, so i think, if the user don't have another 50MB, the app crash!

the error from the play console:

java.lang.OutOfMemoryError: 
  at dalvik.system.VMRuntime.newNonMovableArray (Native Method)
  at android.graphics.BitmapFactory.nativeDecodeAsset (Native Method)
  at android.graphics.BitmapFactory.decodeStream (BitmapFactory.java:620)
  at android.graphics.BitmapFactory.decodeResourceStream (BitmapFactory.java:455)
  at android.graphics.drawable.Drawable.createFromResourceStream (Drawable.java:1152)
  at android.content.res.ResourcesImpl.loadDrawableForCookie (ResourcesImpl.java:857)
  at android.content.res.ResourcesImpl.loadDrawable (ResourcesImpl.java:708)
  at android.content.res.Resources.loadDrawable (Resources.java:863)
  at android.content.res.TypedArray.getDrawable (TypedArray.java:928)
  at android.widget.ImageView.<init> (ImageView.java:157)
  at android.widget.ImageView.<init> (ImageView.java:145)
  at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:71)
  at android.support.v7.widget.AppCompatImageView.<init> (AppCompatImageView.java:67)
  at android.support.v7.app.AppCompatViewInflater.createView (AppCompatViewInflater.java:106)
  at android.support.v7.app.AppCompatDelegateImplV9.createView (AppCompatDelegateImplV9.java:1016)
  at android.support.v7.app.AppCompatDelegateImplV9.onCreateView (AppCompatDelegateImplV9.java:1073)
  at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:769)
  at android.view.LayoutInflater.createViewFromTag (LayoutInflater.java:727)
  at android.view.LayoutInflater.rInflate (LayoutInflater.java:858)
  at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
  at android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
  at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
  at android.view.LayoutInflater.rInflate (LayoutInflater.java:861)
  at android.view.LayoutInflater.rInflateChildren (LayoutInflater.java:821)
  at android.view.LayoutInflater.inflate (LayoutInflater.java:518)
  at android.view.LayoutInflater.inflate (LayoutInflater.java:426)
  at android.view.LayoutInflater.inflate (LayoutInflater.java:377)
  at android.support.v7.app.AppCompatDelegateImplV9.setContentView (AppCompatDelegateImplV9.java:287)
  at android.support.v7.app.AppCompatActivity.setContentView (AppCompatActivity.java:139)
  at com.royijournogmail.designjs.MainActivity.onCreate (MainActivity.java:859)
  at android.app.Activity.performCreate (Activity.java:6757)
  at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1119)
  at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2704)
  at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2812)
  at android.app.ActivityThread.-wrap12 (ActivityThread.java)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1528)
  at android.os.Handler.dispatchMessage (Handler.java:102)
  at android.os.Looper.loop (Looper.java:154)
  at android.app.ActivityThread.main (ActivityThread.java:6311)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:872)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:762)

i am very sure it is not happen because big images, i think it just because the run time usage,after the installation.

some can help what can i do? if i will use library that handle the imageviews, it will help? or can i put in google play that you need 100MB free to download the app? i dont want that for some user the app will crash!.

thanks a lot!