0

I get the following out of memory error and I'm not sure why.

Failed to allocate a 1860508 byte allocation with 905740 free bytes and 884KB until OOM
java.lang.OutOfMemoryError: Failed to allocate a 1860508 byte allocation with 905740 free bytes and 884KB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method) 
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:837)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:656) 
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1037) 
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4056) 
at android.content.res.Resources.loadDrawable(Resources.java:3929) 
at android.content.res.Resources.getDrawable(Resources.java:1991) 
at android.content.res.Resources.getDrawable(Resources.java:1973) 
at android.graphics.drawable.LevelListDrawable.inflate(LevelListDrawable.java:128) 
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1192) 
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1086) 
at android.content.res.Resources.loadDrawableForCookie(Resources.java:4045) 
at android.content.res.Resources.loadDrawable(Resources.java:3929) 
at android.content.res.Resources.getDrawable(Resources.java:1991) 
at android.content.res.Resources.getDrawable(Resources.java:1973) 
at android.content.Context.getDrawable(Context.java:409)
at com.MyCompany.MyApp.Login.updateWifiStatus(Login.java:942)
at com.MyCompany.MyApp.Login6ドル.run(Login.java:576) 
at android.os.Handler.handleCallback(Handler.java:739) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:6939) 
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 

I am using a 5 level resource to indicate wifi status and here is the code I'm using

 WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
 // Level of current connection
 int rssi = wifiManager.getConnectionInfo().getRssi();
 int level = WifiManager.calculateSignalLevel(rssi, 5);
 Drawable db = getDrawable(R.drawable.stat_sys_wifi_signal);
 db.setLevel(level);
 wifiMenu.setIcon(db);

The images are all the same size (512x512).

In reference to other answers out there I have got largeheap in my manifest.

Any help would be greatly appreciated.

Phantômaxx
38.1k21 gold badges88 silver badges122 bronze badges
asked Nov 14, 2017 at 11:08
5
  • what is size if your image in KBs? Commented Nov 14, 2017 at 11:10
  • developer.android.com/topic/performance/graphics/… Commented Nov 14, 2017 at 11:12
  • biggest one is 32kb Commented Nov 14, 2017 at 11:14
  • read the link mentioned link. and pass the Bitmap Options accordingly Commented Nov 14, 2017 at 11:17
  • I've read the link but as I'm using a drawable with levels how do I scale down the image? I can see how it works with r.drawable.image for example but for levels? Commented Nov 14, 2017 at 11:54

1 Answer 1

1

Use TinyPNG

TinyPNG uses smart lossy compression techniques to reduce the file size of your PNG files. By selectively decreasing the number of colors in the image, fewer bytes are required to store the data. The effect is nearly invisible but it makes a very large difference in file size!

Compress all images using this link.

Reduce the size of all picture before use in your Android applications.

Make sure you read the document Loading Large Bitmaps Efficiently given by @mudit_sen.

Hope this may help you.

answered Nov 14, 2017 at 11:17
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for the link to TinyPNG, saved over 50% in size. I've read the link but as I'm using a drawable with levels how do I scale down the image? I can see how it works with r.drawable.image for example but for levels?
Try moving your drawables from lower MPI to HDPI or XHDPI depending on your resolution.
Move the 5 wifi icons into those folders e.g. mipmap-hdpi? What will that do?
Best practice is to add images to all drawable folder. But at that time to just try to move your images in higher resolution folder. Because, If you add all images in only one mdpi folder than system scales default density resources up for high-density screens and down for low-density screens, as appropriate.
Use this link for more reference: developer.android.com/guide/practices/…
|

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.