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.
-
what is size if your image in KBs?mudit_sen– mudit_sen2017年11月14日 11:10:24 +00:00Commented Nov 14, 2017 at 11:10
-
developer.android.com/topic/performance/graphics/…mudit_sen– mudit_sen2017年11月14日 11:12:30 +00:00Commented Nov 14, 2017 at 11:12
-
biggest one is 32kbSliderUK– SliderUK2017年11月14日 11:14:07 +00:00Commented Nov 14, 2017 at 11:14
-
read the link mentioned link. and pass the Bitmap Options accordinglymudit_sen– mudit_sen2017年11月14日 11:17:22 +00:00Commented 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?SliderUK– SliderUK2017年11月14日 11:54:42 +00:00Commented Nov 14, 2017 at 11:54
1 Answer 1
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.
7 Comments
Explore related questions
See similar questions with these tags.