Out of memory Fatal Exception - android

I have an Activity that contains 12 ImageViews. In onCreate method I load 12 photos in these ImageViews using BitmapFactory.decodeStream(...).
When I come to this page and return back for 10 times I get the following Out of Memory Exception.
Why I get this error and how can I release resources to prevent this exception?
Thanks,
04-24 14:41:00.050: D/TextView(7586): Constructor - Got appearance for textColorPrimaryInverse
04-24 14:41:00.050: D/TextView(7586): Constructor -- Got mEditTextBackgroundColor
04-24 14:41:00.130: I/dalvikvm-heap(7586): Clamp target GC heap from 48.878MB to 48.000MB
04-24 14:41:00.130: D/dalvikvm(7586): GC_FOR_ALLOC freed 495K, 2% free 47950K/48775K, paused 44ms
04-24 14:41:00.130: I/dalvikvm-heap(7586): Forcing collection of SoftReferences for 404616-byte allocation
04-24 14:41:00.180: I/dalvikvm-heap(7586): Clamp target GC heap from 48.856MB to 48.000MB
04-24 14:41:00.180: D/dalvikvm(7586): GC_BEFORE_OOM freed 23K, 2% free 47926K/48775K, paused 48ms
04-24 14:41:00.180: E/dalvikvm-heap(7586): Out of memory on a 404616-byte allocation.
04-24 14:41:00.180: I/dalvikvm(7586): "main" prio=5 tid=1 RUNNABLE
04-24 14:41:00.180: I/dalvikvm(7586): | group="main" sCount=0 dsCount=0 obj=0x40a54460 self=0x1ad5828
04-24 14:41:00.180: I/dalvikvm(7586): | sysTid=7586 nice=0 sched=0/0 cgrp=default handle=1074742408
04-24 14:41:00.180: I/dalvikvm(7586): | schedstat=( 14073874000 2242143000 19299 ) utm=1301 stm=106 core=1
04-24 14:41:00.180: I/dalvikvm(7586): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-24 14:41:00.180: I/dalvikvm(7586): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.utils.Utilities.decodeFile(Utilities.java:1220)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.businessLayer.db.BoInvProducts.getProductPhoto(BoInvProducts.java:107)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.ui.ActProductsGallery.loadPageImages(ActProductsGallery.java:729)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.ui.ActProductsGallery.selectItemInGallery(ActProductsGallery.java:611)
04-24 14:41:00.180: I/dalvikvm(7586): at org.mabna.order.ui.ActProductsGallery.onCreate(ActProductsGallery.java:315)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.Activity.performCreate(Activity.java:4465)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-24 14:41:00.180: I/dalvikvm(7586): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 14:41:00.180: I/dalvikvm(7586): at android.os.Looper.loop(Looper.java:137)
04-24 14:41:00.180: I/dalvikvm(7586): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-24 14:41:00.180: I/dalvikvm(7586): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 14:41:00.180: I/dalvikvm(7586): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 14:41:00.180: I/dalvikvm(7586): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-24 14:41:00.180: I/dalvikvm(7586): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-24 14:41:00.180: I/dalvikvm(7586): at dalvik.system.NativeStart.main(Native Method)
04-24 14:41:00.180: D/skia(7586): --- decoder->decode returned false
04-24 14:41:00.180: D/AndroidRuntime(7586): Shutting down VM
04-24 14:41:00.180: W/dalvikvm(7586): threadid=1: thread exiting with uncaught exception (group=0x40a531f8)
04-24 14:41:00.180: E/AndroidRuntime(7586): FATAL EXCEPTION: main
04-24 14:41:00.180: E/AndroidRuntime(7586): java.lang.OutOfMemoryError
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.utils.Utilities.decodeFile(Utilities.java:1220)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.businessLayer.db.BoInvProducts.getProductPhoto(BoInvProducts.java:107)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.ui.ActProductsGallery.loadPageImages(ActProductsGallery.java:729)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.ui.ActProductsGallery.selectItemInGallery(ActProductsGallery.java:611)
04-24 14:41:00.180: E/AndroidRuntime(7586): at org.mabna.order.ui.ActProductsGallery.onCreate(ActProductsGallery.java:315)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.Activity.performCreate(Activity.java:4465)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.os.Looper.loop(Looper.java:137)
04-24 14:41:00.180: E/AndroidRuntime(7586): at android.app.ActivityThread.main(ActivityThread.java:4424)
04-24 14:41:00.180: E/AndroidRuntime(7586): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 14:41:00.180: E/AndroidRuntime(7586): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 14:41:00.180: E/AndroidRuntime(7586): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-24 14:41:00.180: E/AndroidRuntime(7586): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-24 14:41:00.180: E/AndroidRuntime(7586): at dalvik.system.NativeStart.main(Native Method)
04-24 14:41:01.350: I/Process(7586): Sending signal. PID: 7586 SIG: 9

Maybe, decode your images with the nearest size of your ImageViews (see this : Strange out of memory issue while loading an image to a Bitmap object)

Sounds like you are switching activities the wrong way and keeping to many instances in memory. You could try setting FLAG_ACTIVITY_CLEAR_TOP on the intent that opens this activity or take a look at Activity life cycle to figure out where you should load the images.

Have you tried the following?
recycle the bitmaps like this
#Override
public void onDestroy() {
super.onDestroy();
for (int i = 0; i < 5; i++) {
TermElement e = theFiveGaugesInclRPMInPos4[i];
e.background.recycle();
e.background = null;
}
if (DEBUG)
Log.i(this.getClass().getSimpleName(), " <<-"
+ Thread.currentThread().getStackTrace()[2].getMethodName());
}
to reuse the bitmap I define it as static and just init like this:
if (faceTexture == null)
faceTexture = BitmapFactory.decodeResource(getContext()
.getResources(), faceTextureID);
check memory usage with DDMS
Now it doesn't crash anymore.
ps sorry for the formatting - it just doesn't let me format the code correctly anymore - have to reboot? :-(

Related

OutOfMemoryError when loading an animation .xml

I have the following ImageView:
imageView.setBackgroundResource(R.drawable.create_user);
My create_user drawable looks like this:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="#drawable/create_user_0" android:duration="500" />
<item android:drawable="#drawable/create_user_1" android:duration="500" />
</animation-list>
But when the .xml is being set in imageView.setBacgroundResource(R.drawable.create_user), it launches the following exception:
02-04 10:49:07.994: E/AndroidRuntime(1379): FATAL EXCEPTION: main
02-04 10:49:07.994: E/AndroidRuntime(1379): java.lang.OutOfMemoryError
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.content.res.Resources.loadDrawable(Resources.java:2988)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.content.res.Resources.getDrawable(Resources.java:1558)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:282)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.content.res.Resources.loadDrawable(Resources.java:2970)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.content.res.Resources.getDrawable(Resources.java:1558)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.view.View.setBackgroundResource(View.java:15697)
02-04 10:49:07.994: E/AndroidRuntime(1379): at com.facephi.sdk.ui.FragmentCreatingStructure.onCreateView(FragmentCreatingStructu re.java:29)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.Fragment.performCreateView(Fragment.java:1699)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1075)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.BackStackRecord.run(BackStackRecord.java:682)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1455)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.FragmentManagerImpl$1.run(FragmentManager.java:441)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.os.Handler.handleCallback(Handler.java:730)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.os.Handler.dispatchMessage(Handler.java:92)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.os.Looper.loop(Looper.java:176)
02-04 10:49:07.994: E/AndroidRuntime(1379): at android.app.ActivityThread.main(ActivityThread.java:5419)
02-04 10:49:07.994: E/AndroidRuntime(1379): at java.lang.reflect.Method.invokeNative(Native Method)
02-04 10:49:07.994: E/AndroidRuntime(1379): at java.lang.reflect.Method.invoke(Method.java:525)
02-04 10:49:07.994: E/AndroidRuntime(1379): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
02-04 10:49:07.994: E/AndroidRuntime(1379): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
02-04 10:49:07.994: E/AndroidRuntime(1379): at dalvik.system.NativeStart.main(Native Method)
I have to say that I've been using this animation for a looong time. And yesterday was the first time it started crashing.
I can't imagine what's going on at this point... Can anyone help me find what I'm doing wrong?
NOTE: It says Out of memory on a 638416-byte allocation before the mistake is launched.
NOTE2: It also says this several times before the application crashes.
02-04 11:23:56.179: I/dalvikvm(7266): "Binder_1" prio=5 tid=9 RUNNABLE
02-04 11:23:56.179: I/dalvikvm(7266): | group="main" sCount=0 dsCount=0 obj=0x427f2200 self=0x4192fcd0
02-04 11:23:56.179: I/dalvikvm(7266): | sysTid=7277 nice=0 sched=0/0 cgrp=apps handle=1100151432
02-04 11:23:56.179: I/dalvikvm(7266): | state=R schedstat=( 504400204 75428596 671 ) utm=34 stm=15 core=2
02-04 11:23:56.179: I/dalvikvm(7266): at dalvik.system.NativeStart.run(Native Method)
02-04 11:23:56.179: E/Camera-JNI(7266): Couldn't allocate byte array for JPEG data
02-04 11:23:56.239: I/dalvikvm-heap(7266): Clamp target GC heap from 71.012MB to 64.000MB
02-04 11:23:56.239: D/dalvikvm(7266): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 11:23:56.239: D/dalvikvm(7266): GC_FOR_ALLOC freed 21K, 3% free 63352K/65192K, paused 17ms, total 17ms
02-04 11:23:56.239: I/dalvikvm-heap(7266): Forcing collection of SoftReferences for 460816-byte allocation
02-04 11:23:56.259: I/dalvikvm-heap(7266): Clamp target GC heap from 71.012MB to 64.000MB
02-04 11:23:56.259: D/dalvikvm(7266): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 11:23:56.259: D/dalvikvm(7266): GC_BEFORE_OOM freed 0K, 3% free 63352K/65192K, paused 20ms, total 20ms
02-04 11:23:56.259: E/dalvikvm-heap(7266): Out of memory on a 460816-byte allocation.
Try adding android:largeHeap="true", in the manifest to see if this solves it.
Or Use api inSampleSize of bitmapfactory to sample the images.
I also faced this kind of error once but when I re sized my images it got resolved.
Try to re-size your images.
You can try to resize your images to adapt them to the exact size of the view, as explained here. You can even try using libraries like universal image loader which make this task easier.

Android application Error Opening Trace File: No such file or directory

Here is a link to a question i posted before with my code:
https://stackoverflow.com/questions/22277864/grid-view-open-one-layout-form-another-causes-the-prograam-to-crash
The error happens right as I click on the button2 'Ornaments' on the main form .
Log Cat:
03-09 10:08:20.308: E/Trace(640): error opening trace file: No such file or directory (2)
03-09 10:08:21.158: D/libEGL(640): loaded /system/lib/egl/libEGL_emulation.so
03-09 10:08:21.158: D/(640): HostConnection::get() New Host Connection established 0x2a072918, tid 640
03-09 10:08:21.218: D/libEGL(640): loaded /system/lib/egl/libGLESv1_CM_emulation.so
03-09 10:08:21.229: D/libEGL(640): loaded /system/lib/egl/libGLESv2_emulation.so
03-09 10:08:21.338: W/EGL_emulation(640): eglSurfaceAttrib not implemented
03-09 10:08:21.378: D/OpenGLRenderer(640): Enabling debug mode 0
03-09 10:08:26.648: D/dalvikvm(640): GC_FOR_ALLOC freed 125K, 3% free 8250K/8455K, paused 118ms, total 130ms
03-09 10:08:26.648: I/dalvikvm-heap(640): Forcing collection of SoftReferences for 31961104-byte allocation
03-09 10:08:26.838: D/dalvikvm(640): GC_BEFORE_OOM freed 13K, 3% free 8236K/8455K, paused 184ms, total 185ms
03-09 10:08:26.838: E/dalvikvm-heap(640): Out of memory on a 31961104-byte allocation.
03-09 10:08:26.838: I/dalvikvm(640): "main" prio=5 tid=1 RUNNABLE
03-09 10:08:26.848: I/dalvikvm(640): | group="main" sCount=0 dsCount=0 obj=0x40a14568 self=0x2a00b9e0
03-09 10:08:26.848: I/dalvikvm(640): | sysTid=640 nice=0 sched=0/0 cgrp=apps handle=1073870640
03-09 10:08:26.848: I/dalvikvm(640): | schedstat=( 1310216641 1726854966 299 ) utm=92 stm=39 core=0
03-09 10:08:26.858: I/dalvikvm(640): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
03-09 10:08:26.858: I/dalvikvm(640): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)
03-09 10:08:26.858: I/dalvikvm(640): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
03-09 10:08:26.873: I/dalvikvm(640): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
03-09 10:08:26.878: I/dalvikvm(640): at android.content.res.Resources.loadDrawable(Resources.java:1930)
03-09 10:08:26.878: I/dalvikvm(640): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-09 10:08:26.878: I/dalvikvm(640): at android.widget.ImageView.<init>(ImageView.java:120)
03-09 10:08:26.878: I/dalvikvm(640): at android.widget.ImageView.<init>(ImageView.java:110)
03-09 10:08:26.878: I/dalvikvm(640): at java.lang.reflect.Constructor.constructNative(Native Method)
03-09 10:08:26.878: I/dalvikvm(640): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-09 10:08:26.878: I/dalvikvm(640): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-09 10:08:26.888: I/dalvikvm(640): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-09 10:08:26.888: I/dalvikvm(640): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-09 10:08:26.888: I/dalvikvm(640): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-09 10:08:26.888: I/dalvikvm(640): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-09 10:08:26.888: I/dalvikvm(640): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-09 10:08:26.888: I/dalvikvm(640): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-09 10:08:26.898: I/dalvikvm(640): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-09 10:08:26.898: I/dalvikvm(640): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
03-09 10:08:26.898: I/dalvikvm(640): at android.app.Activity.setContentView(Activity.java:1867)
03-09 10:08:26.898: I/dalvikvm(640): at edu.ajh161.designs.Ornaments.onCreate(Ornaments.java:13)
03-09 10:08:26.898: I/dalvikvm(640): at android.app.Activity.performCreate(Activity.java:5008)
03-09 10:08:26.910: I/dalvikvm(640): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-09 10:08:26.910: I/dalvikvm(640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-09 10:08:26.910: I/dalvikvm(640): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-09 10:08:26.910: I/dalvikvm(640): at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-09 10:08:26.910: I/dalvikvm(640): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-09 10:08:26.910: I/dalvikvm(640): at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 10:08:26.910: I/dalvikvm(640): at android.os.Looper.loop(Looper.java:137)
03-09 10:08:26.918: I/dalvikvm(640): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-09 10:08:26.918: I/dalvikvm(640): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 10:08:26.918: I/dalvikvm(640): at java.lang.reflect.Method.invoke(Method.java:511)
03-09 10:08:26.918: I/dalvikvm(640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-09 10:08:26.918: I/dalvikvm(640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-09 10:08:26.918: I/dalvikvm(640): at dalvik.system.NativeStart.main(Native Method)
03-09 10:08:26.928: D/skia(640): --- decoder->decode returned false
03-09 10:08:26.948: D/AndroidRuntime(640): Shutting down VM
03-09 10:08:26.958: W/dalvikvm(640): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
03-09 10:08:27.138: E/AndroidRuntime(640): FATAL EXCEPTION: main
03-09 10:08:27.138: E/AndroidRuntime(640): java.lang.RuntimeException: Unable to start activity ComponentInfo{edu.ajh161.designs/edu.ajh161.designs.Ornaments}: android.view.InflateException: Binary XML file line #34: Error inflating class <unknown>
03-09 10:08:27.138: E/AndroidRuntime(640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.app.ActivityThread.access$600(ActivityThread.java:130)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.os.Handler.dispatchMessage(Handler.java:99)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.os.Looper.loop(Looper.java:137)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.app.ActivityThread.main(ActivityThread.java:4745)
03-09 10:08:27.138: E/AndroidRuntime(640): at java.lang.reflect.Method.invokeNative(Native Method)
03-09 10:08:27.138: E/AndroidRuntime(640): at java.lang.reflect.Method.invoke(Method.java:511)
03-09 10:08:27.138: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
03-09 10:08:27.138: E/AndroidRuntime(640): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
03-09 10:08:27.138: E/AndroidRuntime(640): at dalvik.system.NativeStart.main(Native Method)
03-09 10:08:27.138: E/AndroidRuntime(640): Caused by: android.view.InflateException: Binary XML file line #34: Error inflating class <unknown>
03-09 10:08:27.138: E/AndroidRuntime(640): at android.view.LayoutInflater.createView(LayoutInflater.java:613)
03-09 10:08:27.138: E/AndroidRuntime(640): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
03-09 10:08:27.138: E/AndroidRuntime(640): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.app.Activity.setContentView(Activity.java:1867)
03-09 10:08:27.138: E/AndroidRuntime(640): at edu.ajh161.designs.Ornaments.onCreate(Ornaments.java:13)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.app.Activity.performCreate(Activity.java:5008)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
03-09 10:08:27.138: E/AndroidRuntime(640): ... 11 more
03-09 10:08:27.138: E/AndroidRuntime(640): Caused by: java.lang.reflect.InvocationTargetException
03-09 10:08:27.138: E/AndroidRuntime(640): at java.lang.reflect.Constructor.constructNative(Native Method)
03-09 10:08:27.138: E/AndroidRuntime(640): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
03-09 10:08:27.138: E/AndroidRuntime(640): ... 24 more
03-09 10:08:27.138: E/AndroidRuntime(640): Caused by: java.lang.OutOfMemoryError
03-09 10:08:27.138: E/AndroidRuntime(640): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.content.res.Resources.loadDrawable(Resources.java:1930)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.widget.ImageView.<init>(ImageView.java:120)
03-09 10:08:27.138: E/AndroidRuntime(640): at android.widget.ImageView.<init>(ImageView.java:110)
03-09 10:08:27.138: E/AndroidRuntime(640): ... 27 more
03-09 10:08:31.238: I/Process(640): Sending signal. PID: 640 SIG: 9
Here, you are getting 3 Exceptions:
android.view.InflateException
java.lang.reflect.InvocationTargetException
java.lang.OutOfMemoryError
The problem starts to occurring from OutOfMemoryError Exception. The drawable, you are trying to set in the ImageView with the id imageview2, may be too large. So, when system trying to process that drawable it exceeds memory limit...then OutOfMemoryError Exception occurring.
Since, due to the OutOfMemoryError, system can't set that drawable to tha ImageView then its throwing other Exceptions as InvocationTargetException and InflateException.
Now, try to reduce the drawable's size...may be your problem will be solved.

SplashScreen using PNG image leads to Android.Views.InflateException followed by OutOfMemory

I watched Google IO 2011 conference, read almost every post about OutOfMemory Exception and InflateException, no luck, I cannot find any answer that solve my problem.
How can I properly clear memory from a layout containing a background image? I feel like if the InflateException followed by OutOfMemory are related because that background image is not cleared properly.
So I'm getting :
Android.Views.InflateException: Binary XML file line #24: Error
inflating class
followed by :
Java.Lang.OutOfMemoryError:
Which I'm pretty sure is caused by my background image.
I simplified my code to narrow the problem as much as possible.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="12" android:targetSdkVersion="12" />
<activity />
<application android:theme="#android:style/Theme.NoTitleBar" parent="android:Theme"/>
</manifest>
I added parent="android:Theme" which was suppose to fix the issue, no success.
SplashScreen.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/SplashScreenView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/splash" />
splash is a .png image located in my drawable folder.
SplashScreenActivity.cs
[Activity(Label = "My splash screen", MainLauncher = true)]
public class SplashScreenActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.SplashScreen);
StartNextActivity();
}
private void StartNextActivity()
{
var intent = new Intent(this, typeof(SplashScreenActivity));
intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
StartActivity(intent);
Finish();
}
public override void Finish()
{
base.Finish();
var view = FindViewById<LinearLayout>(Resource.Id.SplashScreenView);
view.Background.SetCallback(null);
view.Background.Dispose();
view.DestroyDrawingCache();
Resources.FlushLayoutCache();
}
}
First I do load the SplashScreenActivity continuously, this is intentional to make the errors happen sooner.
As you can see, I tried several things to clear the Background image, setting flags or explicitly trying to dispose it.
On the first load I get those messages, which seems to be ok since it is loading the image :
07-18 12:14:22.472 I/dalvikvm-heap(30085): Grow heap (frag case) to 10.600MB for 2949136-byte allocation
07-18 12:14:22.522 D/dalvikvm(30085): GC_CONCURRENT freed 76K, 7% free 9432K/10119K, paused 2ms+1ms
However, it keep growing up until I consume all the device available memory :
07-18 12:12:17.852 I/dalvikvm-heap(18665): Clamp target GC heap from 68.605MB to 64.000MB
07-18 12:12:17.852 D/dalvikvm(18665): GC_FOR_ALLOC freed 73K, 1% free 65064K/65543K, paused 338ms
07-18 12:12:17.852 I/dalvikvm-heap(18665): Forcing collection of SoftReferences for 1576-byte allocation
07-18 12:12:18.212 I/dalvikvm-heap(18665): Clamp target GC heap from 68.604MB to 64.000MB
07-18 12:12:18.212 D/dalvikvm(18665): GC_BEFORE_OOM freed <1K, 1% free 65064K/65543K, paused 362ms
07-18 12:12:18.212 E/dalvikvm-heap(18665): Out of memory on a 1576-byte allocation.
07-18 12:12:18.212 I/dalvikvm(18665): "main" prio=5 tid=1 RUNNABLE
07-18 12:12:18.212 I/dalvikvm(18665): | group="main" sCount=0 dsCount=0 obj=0x40a45460 self=0xb068a0
07-18 12:12:18.212 I/dalvikvm(18665): | sysTid=18665 nice=0 sched=0/0 cgrp=default handle=1074517128
07-18 12:12:18.212 I/dalvikvm(18665): | schedstat=( 71462466000 19081532000 88403 ) utm=6360 stm=786 core=0
07-18 12:12:18.212 I/dalvikvm(18665): at android.content.res.Resources.getCachedStyledAttributes(Resources.java:~2193)
07-18 12:12:18.212 I/dalvikvm(18665): at android.content.res.Resources.access$000(Resources.java:71)
07-18 12:12:18.212 I/dalvikvm(18665): at android.content.res.Resources$Theme.obtainStyledAttributes(Resources.java:1260)
07-18 12:12:18.212 I/dalvikvm(18665): at android.content.Context.obtainStyledAttributes(Context.java:364)
07-18 12:12:18.212 I/dalvikvm(18665): at android.view.View.<init>(View.java:2746)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.ViewGroup.<init>(ViewGroup.java:385)
07-18 12:12:18.222 I/dalvikvm(18665): at android.widget.LinearLayout.<init>(LinearLayout.java:174)
07-18 12:12:18.222 I/dalvikvm(18665): at android.widget.LinearLayout.<init>(LinearLayout.java:170)
07-18 12:12:18.222 I/dalvikvm(18665): at java.lang.reflect.Constructor.constructNative(Native Method)
07-18 12:12:18.222 I/dalvikvm(18665): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-18 12:12:18.222 I/dalvikvm(18665): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2707)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2767)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:247)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.Activity.setContentView(Activity.java:1835)
07-18 12:12:18.222 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.n_onCreate(Native Method)
07-18 12:12:18.222 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.onCreate(SplashScreenActivity.java:30)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.Activity.performCreate(Activity.java:4465)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 12:12:18.222 I/dalvikvm(18665): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 12:12:18.222 I/dalvikvm(18665): at android.os.Looper.loop(Looper.java:137)
07-18 12:12:18.222 I/dalvikvm(18665): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 12:12:18.222 I/dalvikvm(18665): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 12:12:18.222 I/dalvikvm(18665): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 12:12:18.222 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 12:12:18.222 I/dalvikvm(18665): at dalvik.system.NativeStart.main(Native Method)
07-18 12:12:18.222 I/dalvikvm(18665):
07-18 12:12:18.972 I/dalvikvm-heap(18665): Clamp target GC heap from 68.623MB to 64.000MB
07-18 12:12:18.972 D/dalvikvm(18665): GC_FOR_ALLOC freed 6K, 1% free 65082K/65543K, paused 341ms
07-18 12:12:18.982 I/dalvikvm-heap(18665): Forcing collection of SoftReferences for 1402-byte allocation
07-18 12:12:19.332 I/dalvikvm-heap(18665): Clamp target GC heap from 68.623MB to 64.000MB
07-18 12:12:19.332 D/dalvikvm(18665): GC_BEFORE_OOM freed <1K, 1% free 65082K/65543K, paused 358ms
07-18 12:12:19.332 E/dalvikvm-heap(18665): Out of memory on a 1402-byte allocation.
07-18 12:12:19.332 I/dalvikvm(18665): "main" prio=5 tid=1 RUNNABLE
07-18 12:12:19.332 I/dalvikvm(18665): | group="main" sCount=0 dsCount=0 obj=0x40a45460 self=0xb068a0
07-18 12:12:19.332 I/dalvikvm(18665): | sysTid=18665 nice=0 sched=0/0 cgrp=default handle=1074517128
07-18 12:12:19.342 I/dalvikvm(18665): | schedstat=( 72173821000 19107690000 88644 ) utm=6429 stm=788 core=0
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~94)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:124)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.StringBuffer.append(StringBuffer.java:278)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.StringWriter.write(StringWriter.java:123)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.doWrite(PrintWriter.java:623)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:601)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:579)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:660)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:722)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:691)
07-18 12:12:19.342 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:31)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:329)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:305)
07-18 12:12:19.342 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.n_onCreate(Native Method)
07-18 12:12:19.342 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.onCreate(SplashScreenActivity.java:30)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.Activity.performCreate(Activity.java:4465)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 12:12:19.342 I/dalvikvm(18665): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 12:12:19.342 I/dalvikvm(18665): at android.os.Looper.loop(Looper.java:137)
07-18 12:12:19.342 I/dalvikvm(18665): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 12:12:19.342 I/dalvikvm(18665): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 12:12:19.342 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 12:12:19.342 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 12:12:19.342 I/dalvikvm(18665): at dalvik.system.NativeStart.main(Native Method)
07-18 12:12:19.342 I/dalvikvm(18665):
Unhandled Exception:
Android.Views.InflateException: Binary XML file line #24: Error inflating class <unknown>
07-18 12:12:24.902 I/dalvikvm-heap(18665): Clamp target GC heap from 68.644MB to 64.000MB
07-18 12:12:24.902 D/dalvikvm(18665): GC_FOR_ALLOC freed 5K, 1% free 65105K/65543K, paused 377ms
07-18 12:12:24.902 I/dalvikvm-heap(18665): Forcing collection of SoftReferences for 1402-byte allocation
07-18 12:12:25.242 I/dalvikvm-heap(18665): Clamp target GC heap from 68.644MB to 64.000MB
07-18 12:12:25.242 D/dalvikvm(18665): GC_BEFORE_OOM freed 0K, 1% free 65105K/65543K, paused 345ms
07-18 12:12:25.242 E/dalvikvm-heap(18665): Out of memory on a 1402-byte allocation.
07-18 12:12:25.242 I/dalvikvm(18665): "main" prio=5 tid=1 RUNNABLE
07-18 12:12:25.242 I/dalvikvm(18665): | group="main" sCount=0 dsCount=0 obj=0x40a45460 self=0xb068a0
07-18 12:12:25.242 I/dalvikvm(18665): | sysTid=18665 nice=0 sched=0/0 cgrp=default handle=1074517128
07-18 12:12:25.242 I/dalvikvm(18665): | schedstat=( 72950645000 19154453000 88901 ) utm=6504 stm=791 core=0
07-18 12:12:25.242 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~94)
07-18 12:12:25.242 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:124)
07-18 12:12:25.242 I/dalvikvm(18665): at java.lang.StringBuffer.append(StringBuffer.java:278)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.StringWriter.write(StringWriter.java:123)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.doWrite(PrintWriter.java:623)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:601)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:579)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:660)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:722)
07-18 12:12:25.242 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:691)
07-18 12:12:25.252 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:31)
07-18 12:12:25.252 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:329)
07-18 12:12:25.252 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:305)
07-18 12:12:25.252 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.n_onCreate(Native Method)
07-18 12:12:25.252 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.onCreate(SplashScreenActivity.java:30)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.Activity.performCreate(Activity.java:4465)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 12:12:25.252 I/dalvikvm(18665): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 12:12:25.252 I/dalvikvm(18665): at android.os.Looper.loop(Looper.java:137)
07-18 12:12:25.252 I/dalvikvm(18665): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 12:12:25.252 I/dalvikvm(18665): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 12:12:25.252 I/dalvikvm(18665): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 12:12:25.252 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 12:12:25.252 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 12:12:25.252 I/dalvikvm(18665): at dalvik.system.NativeStart.main(Native Method)
07-18 12:12:25.252 I/dalvikvm(18665):
07-18 12:12:26.042 I/dalvikvm-heap(18665): Clamp target GC heap from 68.654MB to 64.000MB
07-18 12:12:26.042 D/dalvikvm(18665): GC_FOR_ALLOC freed 4K, 1% free 65114K/65543K, paused 395ms
07-18 12:12:26.042 I/dalvikvm-heap(18665): Forcing collection of SoftReferences for 1126-byte allocation
07-18 12:12:26.392 I/dalvikvm-heap(18665): Clamp target GC heap from 68.654MB to 64.000MB
07-18 12:12:26.392 D/dalvikvm(18665): GC_BEFORE_OOM freed 0K, 1% free 65114K/65543K, paused 344ms
07-18 12:12:26.392 E/dalvikvm-heap(18665): Out of memory on a 1126-byte allocation.
07-18 12:12:26.392 I/dalvikvm(18665): "main" prio=5 tid=1 RUNNABLE
07-18 12:12:26.392 I/dalvikvm(18665): | group="main" sCount=0 dsCount=0 obj=0x40a45460 self=0xb068a0
07-18 12:12:26.392 I/dalvikvm(18665): | sysTid=18665 nice=0 sched=0/0 cgrp=default handle=1074517128
07-18 12:12:26.392 I/dalvikvm(18665): | schedstat=( 73695992000 19195168000 89137 ) utm=6574 stm=795 core=0
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.enlargeBuffer(AbstractStringBuilder.java:~94)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.AbstractStringBuilder.append0(AbstractStringBuilder.java:124)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.StringBuffer.append(StringBuffer.java:278)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.StringWriter.write(StringWriter.java:123)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.doWrite(PrintWriter.java:623)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:601)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:579)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.write(PrintWriter.java:660)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:722)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:691)
07-18 12:12:26.392 I/dalvikvm(18665): at java.io.PrintWriter.append(PrintWriter.java:31)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:329)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.Throwable.printStackTrace(Throwable.java:305)
07-18 12:12:26.392 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.n_onCreate(Native Method)
07-18 12:12:26.392 I/dalvikvm(18665): at myFirstApp.android.activities.SplashScreenActivity.onCreate(SplashScreenActivity.java:30)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.Activity.performCreate(Activity.java:4465)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread.access$600(ActivityThread.java:123)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-18 12:12:26.392 I/dalvikvm(18665): at android.os.Handler.dispatchMessage(Handler.java:99)
07-18 12:12:26.392 I/dalvikvm(18665): at android.os.Looper.loop(Looper.java:137)
07-18 12:12:26.392 I/dalvikvm(18665): at android.app.ActivityThread.main(ActivityThread.java:4424)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.reflect.Method.invokeNative(Native Method)
07-18 12:12:26.392 I/dalvikvm(18665): at java.lang.reflect.Method.invoke(Method.java:511)
07-18 12:12:26.392 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-18 12:12:26.392 I/dalvikvm(18665): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-18 12:12:26.392 I/dalvikvm(18665): at dalvik.system.NativeStart.main(Native Method)
07-18 12:12:26.392 I/dalvikvm(18665):
Unhandled Exception:
Java.Lang.OutOfMemoryError:
Additional information
The image is full screen and is the perfect size for this device (I mean that we don't want to shrink it). 1024x720, 24 bits, not Alpha and it takes 487KB on my disk, but obviously, when Android loads it, it seems to be around 10 MB.
I'm running the code on a Nabi2 tablet, model : NABI2-NV7A which is running Android version 4.0.4 along with Kernel version 3.1.10-00275-g3a4f8c1.
Also note that in Visual Studio in my Application Properties, I am targetting those Android versions:
OK, I found a way to do this without throwing these errors.
Instead of creating a Layout with the Splash Screen, I created a theme, since in your case it is simply an image anyways:
styles.xml
<?xml version="1.0" encoding="utf-8" ?>
<resources>
<style name="SplashTheme" parent="#android:style/Theme.NoTitleBar">
<item name="android:background">#drawable/kitten</item>
</style>
</resources>
Then I created an Activity like this:
using Android.App;
using Android.Content;
using Android.OS;
namespace SplashScreenSample
{
[Activity(Label = "Splushy Splushy", MainLauncher = true, Theme = "#style/SplashTheme")]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle b)
{
base.OnCreate(b);
StartNextActivity();
}
private void StartNextActivity()
{
var intent = new Intent(this, typeof(SplashActivity));
intent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ClearWhenTaskReset);
StartActivity(intent);
Finish();
}
}
}
I tried running this on my phone for 10 minutes or so, without any crash with an image of 1600x1200 of a nice kitten.
I found another solution that helped, but never as much as Cheesebaron's solution.
In both cases, it end up crashing.
Cheesebaron's solution crashes after : 14 minutes
Mine crashes after 3 minutes 28 sec.
Since I'm looping intensively to push the device to its limit, Cheesebaron's solution is surely viable.
In my case, instead of setting android:background="#drawable/splash", I removed that entry and used a private Bitmap field in my activity which I then load and pass it to the background drawable.
private Bitmap _bitmapRef;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var view = FindViewById<LinearLayout>(Resource.Id.SplashScreenView);
_bitmapRef = BitmapFactory.DecodeResource(Resources, Resource.Drawable.splash, new BitmapFactory.Options
{
InPurgeable = true,
InInputShareable = true
});
view.SetBackgroundDrawable(new BitmapDrawable(Resources, _bitmapRef));
StartNextActivity();
}
Then, on the OnDestroy call, I override it to explicitly recycle the bitmap.
protected override void OnDestroy()
{
base.OnDestroy();
if (null != _bitmapRef && !_bitmapRef.IsRecycled)
{
_bitmapRef.Recycle();
_bitmapRef = null;
}
}
It seems to me like if Android have problems when the Bitmap is created at the Activity level.
I have another activities in which I load bitmaps in a list object to display them on screen. The list object is at the Activity level and the bitmaps are inside the list.
In that case, the memory seems to be handled properly when I use the above solution. I don't even have to call recycle on the bitmaps inside the list.
But for the SplashScreen, that solution doesn't seems to be enough.

Android: Error when using QRGen lib to generate QR code

I am trying to generate QRCode image using QRGen library.
I have imported qrgen-1.0.jar file to my project.
I know this question is duplicate.
I have referred following code by this link
public Bitmap qrBitmapFromString(String qrText){
ByteArrayOutputStream out = QRCode.from(qrText).to(ImageType.PNG).withSize(300, 300).stream();
byte[] data = out.toByteArray();
Bitmap bmp = BitmapFactory.decodeByteArray (data,0,data.length, null);
return bmp;
}
But I am getting the following error.
04-24 11:48:57.138: E/AndroidRuntime(824): FATAL EXCEPTION: main
04-24 11:48:57.138: E/AndroidRuntime(824): java.lang.NoClassDefFoundError: net.glxn.qrgen.QRCode
04-24 11:48:57.138: E/AndroidRuntime(824): at com.example.barcodeexample.QRCodeGeneratorActivity.onCreate(QRCodeGeneratorActivity.java:34)
04-24 11:48:57.138: E/AndroidRuntime(824): at android.app.Activity.performCreate(Activity.java:5008)
04-24 11:48:57.138: E/AndroidRuntime(824): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-24 11:48:57.138: E/AndroidRuntime(824): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-24 11:48:57.138: E/AndroidRuntime(824): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-24 11:48:57.138: E/AndroidRuntime(824): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-24 11:48:57.138: E/AndroidRuntime(824): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-24 11:48:57.138: E/AndroidRuntime(824): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 11:48:57.138: E/AndroidRuntime(824): at android.os.Looper.loop(Looper.java:137)
04-24 11:48:57.138: E/AndroidRuntime(824): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-24 11:48:57.138: E/AndroidRuntime(824): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 11:48:57.138: E/AndroidRuntime(824): at java.lang.reflect.Method.invoke(Method.java:511)
04-24 11:48:57.138: E/AndroidRuntime(824): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-24 11:48:57.138: E/AndroidRuntime(824): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-24 11:48:57.138: E/AndroidRuntime(824): at dalvik.system.NativeStart.main(Native Method)
I have imported
import net.glxn.qrgen.QRCode;
import net.glxn.qrgen.image.ImageType;
2.0-SNAPSHOT should solve this https://oss.sonatype.org/content/repositories/snapshots/net/glxn/qrgen/android/2.0-SNAPSHOT/
https://github.com/kenglxn/QRGen
Finally I found and following thing working well for me.
Right click on your project
Go into Build Path
Configure Build Path
Go to Order and Export
Check your OnBarcode library
Clean your project
Think this may help some one like me.
Thanks.

Weird Exception when Livewallpaper is set in Android

04-24 13:30:59.312: VERBOSE/RenderScript(6044): RS Thread exited
04-24 13:30:59.320: ERROR/libEGL(6044): call to OpenGL ES API with no current context (logged once per thread)
04-24 13:30:59.335: WARN/WallpaperService(6044): Ignoring updateSurface: destroyed
04-24 13:30:59.335: WARN/WindowManager(108): Window android.view.IWindow$Stub$Proxy#408968d0 is already added
04-24 13:30:59.355: DEBUG/dalvikvm(6083): GC_EXTERNAL_ALLOC freed 23K, 52% free 2598K/5379K, external 1625K/2137K, paused 55ms
04-24 13:30:59.425: DEBUG/GLWallpaperService(6083): onSurfaceDestroyed()
04-24 13:30:59.496: WARN/InputQueue-JNI(6044): Input channel is not initialized.
04-24 13:30:59.515: DEBUG/AndroidRuntime(6044): Shutting down VM
04-24 13:30:59.539: WARN/dalvikvm(6044): threadid=1: thread exiting with uncaught exception (group=0x40015560)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): FATAL EXCEPTION: main
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): java.lang.RuntimeException: Failed to register input channel. Check logs for details.
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at android.view.InputQueue.nativeRegisterInputChannel(Native Method)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at android.view.InputQueue.registerInputChannel(InputQueue.java:92)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at android.service.wallpaper.WallpaperService$Engine.updateSurface(WallpaperService.java:521)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:904)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at android.os.Looper.loop(Looper.java:123)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at android.app.ActivityThread.main(ActivityThread.java:3683)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at java.lang.reflect.Method.invokeNative(Native Method)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at java.lang.reflect.Method.invoke(Method.java:507)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-24 13:30:59.640: ERROR/AndroidRuntime(6044): at dalvik.system.NativeStart.main(Native Method)
I was developing a Livewallpaper which uses a open-source game engine called Andengine(andengine.org), it works fine now except sometimes when user set my Livewallpaper as wall paper, an Exception will be thrown saying "Failed to register input channel. Check logs for details.", but the werid thing is the Livewallpaper still works and did not exit.
Any idea what maybe causing this problem , or how I can fix it?
Sorry, I could only find that the InputQueue "provides a mechanism for an application to receive incoming input events. Currently only usable from native code".
Check the GLSurfaceView class in andengine. That may give you a clue of what is wrong with your wallpaper
You may also want to check why this is happening:
04-24 13:30:59.320: ERROR/libEGL(6044): call to OpenGL ES API with no current context (logged once per thread)

Categories

Resources