I am, using nearly 90 very big images,and i am using lazy loading for displaying that images in Gallery,and grid view.so after loading the images ,if you click on any button,it giving outofmemory(oom) error,and sometimes it giving Xml binary inflate exception.
I am using very big images,equal to tablet size images,and my apk size is 25MB,.and i am using single activity with multiple FrameLayouts but before loading new View I am removing current view but still problem is there,I dont know why it is happening ?Its giving the oom error but its not giving the exact location of error,and its giving error at random position and error coming frequently.
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): FATAL EXCEPTION: main
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): android.view.InflateException: Binary XML file line #13: Error inflating class <unknown>
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.LayoutInflater.createView(LayoutInflater.java:596)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at com.maheshbabu.app.JustIn.initialize(JustIn.java:143)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at com.maheshbabu.app.JustIn.<init>(JustIn.java:135)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at com.maheshbabu.app.MaheshBabuHomePage.showLatestPage(MaheshBabuHomePage.java:671)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at com.maheshbabu.app.MaheshBabuHomePage.onClick(MaheshBabuHomePage.java:363)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.View.performClick(View.java:3110)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.View$PerformClick.run(View.java:11934)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.os.Handler.handleCallback(Handler.java:587)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.os.Handler.dispatchMessage(Handler.java:92)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.os.Looper.loop(Looper.java:132)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.app.ActivityThread.main(ActivityThread.java:4123)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at java.lang.reflect.Method.invokeNative(Native Method)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at java.lang.reflect.Method.invoke(Method.java:491)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at dalvik.system.NativeStart.main(Native Method)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): Caused by: java.lang.reflect.InvocationTargetException
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at java.lang.reflect.Constructor.constructNative(Native Method)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at java.lang.reflect.Constructor.newInstance(Constructor.java:416)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.LayoutInflater.createView(LayoutInflater.java:576)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): ... 21 more
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): Caused by: java.lang.OutOfMemoryError
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:738)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.content.res.Resources.loadDrawable(Resources.java:1918)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.View.<init>(View.java:2450)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.View.<init>(View.java:2389)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.view.ViewGroup.<init>(ViewGroup.java:359)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): at android.widget.RelativeLayout.<init>(RelativeLayout.java:173)
09-30 15:23:07.490: ERROR/AndroidRuntime(5527): ... 24 more
I think this exception is comming from
line this may be because of various reasons.
1) Because you are changing your screen orientation from potrait to landscape and vice versa
Sol) Fix your view to any one orientation. Actually on orientation change new views and new objects are created along with old view and object . thus taking your memory
2) Objects are not freed
sol) Removing views will not solve your problem you have to free all the objects related to those views. Call Bitmap.recycle() on every image related to those views.
also check out these links which may be helpful to you
How to get rid of out of memory exception
Check out this video which may be very useful for you
Memory management for Android Apps
Happy coding friend