In my app, I have 7 radio buttons, each will take you to a specific activity. So in totality, I have 8 activities (home and 7 inner activities).
Each of the 7 inner activities, has a ViewFlipper
, which contains 5 to 8 views.
When I run this app on device with OS version-2.2 or on device with OS version-2.3.3, it's working fine but when I ran the same app on device with OS version-4.0, it throws java.lang.OutOfMemoryError, infrequently (anywhere, for e.g. 3rd screen of 2nd activity's ViewFlipper
).
This link on SO suggests to increase "Max VM application heap size", but since I'm testing on device, it's not possible.
This other link suggests to sample the bitmaps. I do use 15-20 images per activity(1 as background for each of the 5-8 screens and some additional images), but I set all the images in respective xml files only. I don't do anything to bitmaps in code.
At one place, I also found to use unbindDrawables() which I have place in onDestroy() of each activity, but to no avail.
Moreover, if memory is the real issue, then how come it works on 2.2 and 2.3.3 and doesn't work on 4.0 device which has updated OS and overall better configuration.
Is there some bug in OS version 4.0 related to this?
Can anyone guide me please?
Edit(1)
Logcat
android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:606)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:823)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:729)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:742)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
at android.app.Activity.setContentView(Activity.java:1835)
at MYACTIVITYNAME.onCreate(MemberActivity.java:167)
at android.app.Activity.performCreate(Activity.java:4465)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
at android.app.ActivityThread.access$600(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4424)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
at android.view.LayoutInflater.createView(LayoutInflater.java:586)
... 27 more
Caused by: java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
at android.content.res.Resources.loadDrawable(Resources.java:1935)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.ImageView.<init>(ImageView.java:119)
at android.widget.ImageView.<init>(ImageView.java:109)
... 30 more