7

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 around 60mb. While I am loading the app in normal devices we are not facing any problem, But the devices having 2K resolutions such as Nexus 6P, HTC, LG etc., the apps get crash in the middle of the process with the error "Out Of Memory". I have produced the error report with this. I have tried to bitmap factory also. At the same time I am using videos in array method.

Can anyone help with this issue?

FATAL EXCEPTION: main Process: com.example.we.appname, PID: 9353

java.lang.OutOfMemoryError: Failed to allocate a 1660396 byte allocation with 1243880 free bytes and 1214KB until OOM 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:1155) at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:720) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at android.content.res.Resources.loadDrawable(Resources.java:858) at android.content.res.TypedArray.getDrawable(TypedArray.java:928) at android.graphics.drawable.AnimationDrawable.inflateChildElements(AnimationDrawable.java:327) at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:297) at android.graphics.drawable.DrawableInflater.inflateFromXml(DrawableInflater.java:130) at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1227) at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1200) at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:715) at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:571) at android.content.res.Resources.getDrawable(Resources.java:771) at android.content.Context.getDrawable(Context.java:525) at android.view.View.setBackgroundResource(View.java:18228) at com.example.kq.meettheshps.Score_Card.onCreate(Score_Card.java:58) at android.app.Activity.performCreate(Activity.java:6679) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:154) at android.app.ActivityThread.main(ActivityThread.java:6119) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

asked Dec 16, 2016 at 12:13
1

4 Answers 4

16

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">
answered Jun 2, 2017 at 15:16
Sign up to request clarification or add additional context in comments.

3 Comments

Why should hardwareAccelerated to be false?
hardwareAccelerated = false will impact animations, shadows, and elevation and make them look bad.
As I heard, the largeHeap isn't recommended as it can cause other issues and is not a permanent solution.
4

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.

ॐ Rakesh Kumar
1,3141 gold badge14 silver badges24 bronze badges
answered Jan 29, 2018 at 12:30

Comments

2

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.

answered Dec 16, 2016 at 12:50

Comments

0

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.

Mika Sundland
19.1k16 gold badges41 silver badges53 bronze badges
answered Dec 26, 2017 at 14:50

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.