Discussion Forums  >  Crashes, Memory Warnings

Replies: 9    Views: 1852

g1pro757
Android Fan
Profile
Posts: 12
Reg: Feb 12, 2015
new york
120
04/07/15 07:50 AM (2 years ago)

Out of memory error on certain devices

I have a radio streaming application and its been working really well(updated twice already) and am getting good feedback. The problem is that there are very few devices that are giving an out of memory error (specifically the Note 4). I am using the Cp_stream plugin,custom url,custom html text and the location plugin. This is the error im getting back. I know the phone is running out of memory but im not sure how to fix it.

android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:640)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:55)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:689)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:748)
at android.view.LayoutInflater.inflate(LayoutInflater.java:483)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at com.radioalmacristiana.Cp_stream.onCreateView(Cp_stream.java:99)
at android.app.Fragment.performCreateView(Fragment.java:2114)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:904)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1082)
at android.app.BackStackRecord.run(BackStackRecord.java:833)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
at android.app.FragmentManagerImpl$1.run(FragmentManager.java:452)
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:5974)
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:1388)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
at android.view.LayoutInflater.createView(LayoutInflater.java:614)
... 20 more
Caused by: java.lang.OutOfMemoryError: Failed to allocate a 132710412 byte allocation with 8388608 free bytes and 102MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:726)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:547)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:3744)
at android.content.res.Resources.loadDrawable(Resources.java:3617)
at android.content.res.TypedArray.getDrawable(TypedArray.java:762)
at android.view.View.<init>(View.java:3964)
at android.view.ViewGroup.<init>(ViewGroup.java:507)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:249)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:245)
at android.widget.RelativeLayout.<init>(RelativeLayout.java:241)
... 23 more
 
LA
Aspiring developer
Profile
Posts: 3270
Reg: Aug 16, 2012
Jerseyville, IL
42,800
like
04/07/15 08:23 AM (2 years ago)
You have a lot in your drawable folder?



LA
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
04/07/15 08:42 AM (2 years ago)
Could be just the device doesn't have enough memory to deal with what's going on. Some are like that.

Also...related to what @LA said...if you have stuff ONLY in your res > drawable folder, sometimes it's good to have copies in all the other drawable folders. That way it doesn't have to manipulate the images in the res > drawable folder for different devices, which has caused problems.

Mark
 
g1pro757
Android Fan
Profile
Posts: 12
Reg: Feb 12, 2015
new york
120
like
04/07/15 09:17 AM (2 years ago)
Im working on cutting down on some of those bt icons that I dont need. Thanks for the quick response. I will see if it works if not I will be back
 
SmugWimp
Smugger than thou...
Profile
Posts: 6267
Reg: Nov 07, 2012
Tamuning, GU
80,920
like
04/07/15 07:17 PM (2 years ago)
I nod my head to what LA and GNW are saying...

I've found that android devices, because they are so inexpensive (comparatively) that they don't have the same specifications as other devices that cost more; namely RAM.

As such, every once in a while I get the same situation. the only real recourse is to start doing some serious thought about image, image resolution, and image sizing, and quantity.

Don't use 24 color bit if 8 bit will do; don't use 8 bit if 4 bit works. This is related to the 'number' of colors used, not necessarily the 'resolution' of the image, so if you're not using too many colors, 4 bit has a very small file size and works wonders in Android.

The directories in /res are usually 'tailored' to the device resolution. For instance, 'res/drawable' is the default directory that Android uses. If you have a high resolution device (like many are today) then it checks the /res/drawable-hdpi directory for an image. If it doesn't find an image there, it checks /res/drawable. Typically /res/drawable is for mdpi resolution images. So, I usually leave ldpi and mdpi empty, and only concern myself with /res/drawable, res/drawable-hdpi, and res/drawable-xhdpi directories. That drops the total size down a smidgeon, which sometimes is enough.

Usually the most savings is from reducing number of colors. If it's a graphic, and not a picture, that works out ok most of the time...

It's a delicate balance, and at the moment there isn't a single good way to do it; every situation is different. All I can say is work it as best you can.

Cheers!

-- Smug
 
FunkyMonkey
Aspiring developer
Profile
Posts: 1048
Reg: Aug 07, 2013
blackpool
13,280
like
04/08/15 12:08 AM (2 years ago)
when i had problems with android and devices running out of memory (which was many times) i checked the box in the manifest file saying use large heaps,ie (yes) and the memory crashes stopped, hope that helps
cheers
sean
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
04/08/15 01:55 AM (2 years ago)
I have seen *A LOT* of BT 3.0 android memory errors with certain devices, mostly Samsung. Oddly, in my experience, this was much better with Android BT 2.0, but I don't see that as a good option going forwards.

My theory is that if your android app has to manage images, that provokes a memory management problem. Your app hits a certain device memory threshold, the core decides it has run out of memory and the app crashes. Sometimes the even app crashes before it has loaded.

I have gathered a few different tips and tricks, which is still work in progress, but here are my best ones that I know have an effect:

1) Set in the manifest android:largeHeap="true”, which helps by giving app more memory (as mentioned by Sean). I have not found a downside to this tweak. It might give you enough extra memory.

2) If your app references images as URL's, move them into the project and your app will be more stable.

3) To see if the graphics are part of the problem, I have an alternative suggestion to moving all your graphics into the different res drawables, which produces a similar result. Set android:anyDensity=“false” in the android manifest. I believe this has the same benefit as copying un-resized graphics into the different res drawable folders, with the benefit of not increasing the size of the app payload and being easier to manage. There is a side-effect on the positioning of the action bar (where the context menu appears). To remedy that, add the following to to the "<supports screen" section of the android manifest: android:largestWidthLimitDp=“1024”

4) While you are in the manifest, it might be worth setting android:installLocation="preferExternal” which helps the device by using not using core memory to store the app.

5) Try using colour backrounds instead of image backgrounds. If you really need image based backgrounds, I got this tip from Susan Metoxen - use oversized square backgrounds and set in control panel to ‘centre’, to avoid any zooming. Then optimise the graphic sizes in the various res>drawable folders to minimise the app expending memory by trying to scale them. I even went as far as to start developing a table of image sizes for different devices for the xdpi, hdpi and mdpi folders.

6) Try different menus. Different menu's have different memory requirements. For example, on a recent work in progress, I cannot seem to get the buttons menu to run, although the menu with image is fine.

I have to say, developing a decent stable app for android is Really Irritating.

Let us know how you get on, Alan
 
SmugWimp
Smugger than thou...
Profile
Posts: 6267
Reg: Nov 07, 2012
Tamuning, GU
80,920
like
04/08/15 03:40 AM (2 years ago)
Alan,

I wasn't aware of a lot of that. Thanks to you and Sean for bringing those to light. ALL of those tips are going into my checklist.

Cheers!

-- Smug
 
LA
Aspiring developer
Profile
Posts: 3270
Reg: Aug 16, 2012
Jerseyville, IL
42,800
like
04/08/15 05:32 AM (2 years ago)
All great tips and suggestions gang! The reason I automatically was drawn to your drawable folder because logcat, you posted, mentions it. Another tip is uninstall an app on your device to see if that works. You can always reinstall that app.


LA
 
g1pro757
Android Fan
Profile
Posts: 12
Reg: Feb 12, 2015
new york
120
like
04/10/15 06:56 AM (2 years ago)
I will try these solutions and will get back to you guys as soon as I have implemented them. Hopefully this can solve this problem because specifically this is the device we use so it doesn't help us. Thanks for all the suggestions as they also amplified my knowledge.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.