I am trying to add a background image to the activity by android:background=#drawable/.. as shown in the code below. But the problem is, when i add this line android:background="#drawable/introbackground" the app crashs, and when i delete it the app works normally.
To note: the image i use, i have resized it so that, it fits the entire screen. is this could be the problem?
XML:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/introbackground"
android:gravity="center"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.meetingpointlocator_03"
>
LOGCAT OutPut:
05-10 08:06:24.101: D/dalvikvm(17707): GC_FOR_ALLOC freed 119K, 15% free 9922K/11580K,
paused 15ms, total 15ms
05-10 08:06:24.101: I/dalvikvm-heap(17707): Forcing collection of SoftReferences for
121925780-byte allocation
05-10 08:06:24.131: D/dalvikvm(17707): GC_BEFORE_OOM freed 9K, 15% free 9912K/11580K,
paused 30ms, total 30ms
05-10 08:06:24.131: E/dalvikvm-heap(17707): Out of memory on a 121925780-byte
allocation.
05-10 08:06:24.131: I/dalvikvm(17707): "main" prio=5 tid=1 RUNNABLE
05-10 08:06:24.131: I/dalvikvm(17707): | group="main" sCount=0 dsCount=0
obj=0x41c96578 self=0x41c1ca60
05-10 08:06:24.131: I/dalvikvm(17707): | sysTid=17707 nice=-8 sched=0/0 cgrp=apps
handle=1074503676
05-10 08:06:24.131: I/dalvikvm(17707): | state=R schedstat=( 107360003 8309669 119 )
utm=6 stm=4 core=1
05-10 08:06:24.131: I/dalvikvm(17707): at
android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-10 08:06:24.131: I/dalvikvm(17707): at
android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
05-10 08:06:24.131: I/dalvikvm(17707): at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
05-10 08:06:24.131: I/dalvikvm(17707): at
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
05-10 08:06:24.131: I/dalvikvm(17707): at
android.content.res.Resources.loadDrawable(Resources.java:2988)
05-10 08:06:24.131: I/dalvikvm(17707): at
android.content.res.TypedArray.getDrawable(TypedArray.java:602)
05-10 08:06:24.131: I/dalvikvm(17707): at android.view.View.<init>(View.java:3563)
05-10 08:06:24.131: I/dalvikvm(17707): at android.view.ViewGroup.<init>
(ViewGroup.java:475)
05-10 08:06:24.131: I/dalvikvm(17707): at android.widget.LinearLayout.<init>
(LinearLayout.java:176)
05-10 08:06:24.131: I/dalvikvm(17707): at android.widget.LinearLayout.<init>
(LinearLayout.java:172)
05-10 08:06:24.131: I/dalvikvm(17707): at
java.lang.reflect.Constructor.constructNative(Native Method)
05-10 08:06:24.131: I/dalvikvm(17707): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-10 08:06:24.131: I/dalvikvm(17707): at android.view.LayoutInflater.createView(LayoutInflater.java:600)
05-10 08:06:24.131: I/dalvikvm(17707): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-10 08:06:24.131: I/dalvikvm(17707): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:675)
05-10 08:06:24.131: I/dalvikvm(17707): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:700)
05-10 08:06:24.131: I/dalvikvm(17707): at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
05-10 08:06:24.131: I/dalvikvm(17707): at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
05-10 08:06:24.131: I/dalvikvm(17707): at android.view.LayoutInflater.inflate(LayoutInflater.java:354)
05-10 08:06:24.131: I/dalvikvm(17707): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:361)
05-10 08:06:24.131: I/dalvikvm(17707): at android.app.Activity.setContentView(Activity.java:1956)
05-10 08:06:24.131: I/dalvikvm(17707): at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
05-10 08:06:24.131: I/dalvikvm(17707): at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:111)
05-10 08:06:24.131: I/dalvikvm(17707): at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
05-10 08:06:24.131: I/dalvikvm(17707): at com.example.meetingpointlocator_03.Intro.onCreate(Intro.java:38)
05-10 08:06:24.131: I/dalvikvm(17707): at android.app.Activity.performCreate(Activity.java:5372)
05-10 08:06:24.131: I/dalvikvm(17707): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
Out of memory on a 121925780-byte allocation.
You app ran out of memory.
To note: the image i use, i have resized it so that, it fits the
entire screen. is this could be the problem?
Yes the likely cause is this background image which needs to be scaled down. Each app is allocated a certain heap size. As of android 3.0 and above bitmap pixel data is stored in the heap. You need to scale down the image.
Out of Memory error with Bitmap
Also read Load a Scaled Down Version into Memory
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
You are getting OOM i.e out of memory and also the inflator exception at
android:background="#drawable/introbackground"
because the image introbackground is of very large size.
Solution
Use a .jpeg light weight image insted of using .png heavy image.
Related
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.
I'm getting an ANR that seems to be from Toast.makeText:
DALVIK THREADS: (mutexes: tll=0 tsl=0 tscl=0 ghl=0 hwl=0 hwll=0)
"main" prio=5 tid=1 SUSPENDED | group="main" sCount=1 dsCount=0
obj=0x40163600 self=0x12620 | sysTid=4197 nice=0 sched=0/0
cgrp=default handle=-1345338264 | schedstat=( 149532214000 43042125000
324000 ) utm=13923 stm=1030 core=0 at
android.graphics.Matrix.native_create(Native Method) at
android.graphics.Matrix.(Matrix.java:49) at
android.view.View.(View.java:1852) at
android.view.View.(View.java:2411) at
android.view.ViewGroup.(ViewGroup.java:365) at
android.widget.LinearLayout.(LinearLayout.java:156) at
android.widget.LinearLayout.(LinearLayout.java:152) at
java.lang.reflect.Constructor.constructNative(Native Method) at
java.lang.reflect.Constructor.newInstance(Constructor.java:416) at
android.view.LayoutInflater.createView(LayoutInflater.java:576) at
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
at android.view.LayoutInflater.inflate(LayoutInflater.java:457) at
android.view.LayoutInflater.inflate(LayoutInflater.java:391) at
android.view.LayoutInflater.inflate(LayoutInflater.java:347) at
android.widget.Toast.makeText(Toast.java:230) at
android.widget.Toast.makeText(Toast.java:253) at
com.anthonymandra.framework.ViewerActivity.onActivityResult(ViewerActivity.java:802)
at android.app.Activity.dispatchActivityResult(Activity.java:4581) at
android.app.ActivityThread.deliverResults(ActivityThread.java:2814) at
android.app.ActivityThread.handleSendResult(ActivityThread.java:2861)
at android.app.ActivityThread.access$1000(ActivityThread.java:122) at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1054)
at android.os.Handler.dispatchMessage(Handler.java:99) at
android.os.Looper.loop(Looper.java:132) at
android.app.ActivityThread.main(ActivityThread.java:4123) at
java.lang.reflect.Method.invokeNative(Native Method) at
java.lang.reflect.Method.invoke(Method.java:491) at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) at
dalvik.system.NativeStart.main(Native Method)
This is the line of code called from within onActivityResult:
Toast.makeText(this, R.string.save_success, Toast.LENGTH_SHORT).show();
Anyone know why a Toast might cause an ANR, or what might really be wrong if I'm misreading this? Thanks!
Instead of using direct call to R.string, you should use getResources() and then like below
String strSuccess = getString(R.string.save_success);
Toast.makeText(this, strSuccess, Toast.LENGTH_SHORT).show();
or
Toast.makeText(this, getString(R.string.save_success),Toast.LENGTH_SHORT).show();
Read more
I am using FragmentActivity in my application with several Fragments. Each of these fragments hold an image and some text with animation. When user swipes on the screen, the fragment changes.
Now I have been working on this since 10 days and have tested the FragmentActivity on different devices with different Android versions. The reason that I am stuck on this from last 10 days is I am getting a crash
Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 27830 (ple.myfragexample)
Now, this error occurs only when I test the FragmentActivity on Android 4.1.2 particularly. It would run fine on Android 2.3.3, 4.0.3, 4.0.4, 4.2 and even 2.2. The error log is as below:
08-07 14:34:13.843: D/dalvikvm(27830): GC_FOR_ALLOC freed 3845K, 14% free 35407K/40903K, paused 4ms, total 14ms
08-07 14:34:13.848: I/dalvikvm-heap(27830): Grow heap (frag case) to 39.590MB for 3932176-byte allocation
08-07 14:34:13.878: D/dalvikvm(27830): GC_CONCURRENT freed 3K, 5% free 39244K/40903K, paused 11ms+4ms, total 30ms
08-07 14:34:13.928: D/dalvikvm(27830): GC_FOR_ALLOC freed 0K, 5% free 39244K/40903K, paused 16ms, total 16ms
08-07 14:34:13.928: I/dalvikvm-heap(27830): Forcing collection of SoftReferences for 8847376-byte allocation
08-07 14:34:13.953: D/dalvikvm(27830): GC_BEFORE_OOM freed 9K, 5% free 39235K/40903K, paused 24ms, total 24ms
08-07 14:34:13.953: E/dalvikvm-heap(27830): Out of memory on a 8847376-byte allocation.
08-07 14:34:13.953: I/dalvikvm(27830): "main" prio=5 tid=1 RUNNABLE
08-07 14:34:13.953: I/dalvikvm(27830): | group="main" sCount=0 dsCount=0 obj=0x41ea8508 self=0x41e989c8
08-07 14:34:13.953: I/dalvikvm(27830): | sysTid=27830 nice=0 sched=0/0 cgrp=apps handle=1074937648
08-07 14:34:13.953: I/dalvikvm(27830): | schedstat=( 2591504030 1697770606 13588 ) utm=221 stm=38 core=0
08-07 14:34:13.953: I/dalvikvm(27830): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-07 14:34:13.953: I/dalvikvm(27830): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:625)
08-07 14:34:13.953: I/dalvikvm(27830): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:478)
08-07 14:34:13.953: I/dalvikvm(27830): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
08-07 14:34:13.953: I/dalvikvm(27830): at android.content.res.Resources.loadDrawable(Resources.java:1963)
08-07 14:34:13.953: I/dalvikvm(27830): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-07 14:34:13.953: I/dalvikvm(27830): at android.view.View.<init>(View.java:3449)
08-07 14:34:13.953: I/dalvikvm(27830): at android.widget.ImageView.<init>(ImageView.java:114)
08-07 14:34:13.953: I/dalvikvm(27830): at android.widget.ImageView.<init>(ImageView.java:110)
08-07 14:34:13.953: I/dalvikvm(27830): at java.lang.reflect.Constructor.constructNative(Native Method)
08-07 14:34:13.953: I/dalvikvm(27830): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
08-07 14:34:13.953: I/dalvikvm(27830): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
08-07 14:34:13.953: I/dalvikvm(27830): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-07 14:34:13.953: I/dalvikvm(27830): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
08-07 14:34:13.953: I/dalvikvm(27830): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
08-07 14:34:13.953: I/dalvikvm(27830): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
08-07 14:34:13.953: I/dalvikvm(27830): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-07 14:34:13.953: I/dalvikvm(27830): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-07 14:34:13.953: I/dalvikvm(27830): at com.example.myfragexample.pages.Page6.onCreateView(Page6.java:52)
08-07 14:34:13.953: I/dalvikvm(27830): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
08-07 14:34:13.953: I/dalvikvm(27830): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:911)
08-07 14:34:13.953: I/dalvikvm(27830): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)
08-07 14:34:13.953: I/dalvikvm(27830): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
08-07 14:34:13.953: I/dalvikvm(27830): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)
08-07 14:34:13.953: I/dalvikvm(27830): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:429)
08-07 14:34:13.953: I/dalvikvm(27830): at android.os.Handler.handleCallback(Handler.java:615)
08-07 14:34:13.953: I/dalvikvm(27830): at android.os.Handler.dispatchMessage(Handler.java:92)
08-07 14:34:13.953: I/dalvikvm(27830): at android.os.Looper.loop(Looper.java:137)
08-07 14:34:13.953: I/dalvikvm(27830): at android.app.ActivityThread.main(ActivityThread.java:4921)
08-07 14:34:13.953: I/dalvikvm(27830): at java.lang.reflect.Method.invokeNative(Native Method)
08-07 14:34:13.953: I/dalvikvm(27830): at java.lang.reflect.Method.invoke(Method.java:511)
08-07 14:34:13.953: I/dalvikvm(27830): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
08-07 14:34:13.953: I/dalvikvm(27830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
08-07 14:34:13.953: I/dalvikvm(27830): at dalvik.system.NativeStart.main(Native Method)
08-07 14:34:13.953: A/libc(27830): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 27830 (ple.myfragexample)
I have searched a lot over the internet and tried many thing about this, however, the working of my Fragments got smoother on devices with any other version of Android, but just on Android 4.1.2. I also tried to use Universal Image Loader, but it still crashes with Fatal signal 11. The error log I get when I am using Universal Image Loader is as below:
08-07 14:20:03.678: D/dalvikvm(27268): GC_FOR_ALLOC freed 3857K, 32% free 33002K/48455K, paused 31ms, total 34ms
08-07 14:20:03.678: I/dalvikvm-heap(27268): Grow heap (frag case) to 37.241MB for 3932176-byte allocation
08-07 14:20:03.708: D/dalvikvm(27268): GC_FOR_ALLOC freed 5K, 24% free 36837K/48455K, paused 28ms, total 28ms
08-07 14:20:03.738: D/dalvikvm(27268): GC_CONCURRENT freed <1K, 24% free 36837K/48455K, paused 11ms+2ms, total 30ms
08-07 14:20:03.848: D/dalvikvm(27268): GC_FOR_ALLOC freed <1K, 24% free 36837K/48455K, paused 17ms, total 17ms
08-07 14:20:03.848: I/dalvikvm-heap(27268): Forcing collection of SoftReferences for 8847376-byte allocation
08-07 14:20:03.883: D/dalvikvm(27268): GC_BEFORE_OOM freed 9K, 24% free 36828K/48455K, paused 32ms, total 35ms
08-07 14:20:03.883: E/dalvikvm-heap(27268): Out of memory on a 8847376-byte allocation.
08-07 14:20:03.888: I/dalvikvm(27268): "pool-1-thread-1" prio=4 tid=12 RUNNABLE
08-07 14:20:03.888: I/dalvikvm(27268): | group="main" sCount=0 dsCount=0 obj=0x4293af60 self=0x4f6c9470
08-07 14:20:03.888: I/dalvikvm(27268): | sysTid=27283 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1098606736
08-07 14:20:03.888: I/dalvikvm(27268): | schedstat=( 2735922613 2106917058 1146 ) utm=266 stm=7 core=0
08-07 14:20:03.888: I/dalvikvm(27268): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
08-07 14:20:03.888: I/dalvikvm(27268): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:625)
08-07 14:20:03.888: I/dalvikvm(27268): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:478)
08-07 14:20:03.888: I/dalvikvm(27268): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
08-07 14:20:03.888: I/dalvikvm(27268): at android.content.res.Resources.loadDrawable(Resources.java:1963)
08-07 14:20:03.888: I/dalvikvm(27268): at android.content.res.Resources.getDrawable(Resources.java:672)
08-07 14:20:03.888: I/dalvikvm(27268): at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStreamFromDrawable(BaseImageDownloader.java:184)
08-07 14:20:03.888: I/dalvikvm(27268): at com.nostra13.universalimageloader.core.download.BaseImageDownloader.getStream(BaseImageDownloader.java:84)
08-07 14:20:03.888: I/dalvikvm(27268): at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.getImageStream(BaseImageDecoder.java:82)
08-07 14:20:03.888: I/dalvikvm(27268): at com.nostra13.universalimageloader.core.decode.BaseImageDecoder.decode(BaseImageDecoder.java:68)
08-07 14:20:03.888: I/dalvikvm(27268): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.decodeImage(LoadAndDisplayImageTask.java:284)
08-07 14:20:03.888: I/dalvikvm(27268): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.tryLoadBitmap(LoadAndDisplayImageTask.java:243)
08-07 14:20:03.888: I/dalvikvm(27268): at com.nostra13.universalimageloader.core.LoadAndDisplayImageTask.run(LoadAndDisplayImageTask.java:125)
08-07 14:20:03.888: I/dalvikvm(27268): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-07 14:20:03.888: I/dalvikvm(27268): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-07 14:20:03.888: I/dalvikvm(27268): at java.lang.Thread.run(Thread.java:856)
08-07 14:20:03.888: A/libc(27268): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 27283 (pool-1-thread-1)
Now, I know there are lots of questions with Fatal signal 11 on here too, but I am concerned and confused as I am getting this crash only on Android 4.1.2 and not on any other Android versions.
My issue is solved now. I just got my images re-sized from my Graphics team. Previously I was using 1280x768 resolution images but I got them scaled down to 800x480 and the crash is gone. Thanks for all the suggestions though.
Also, I think Jelly Bean (4.x) has enhanced UI and so, it occupies more memory for handling the UI itself than the lower versions of Android, and that's why it was not able to manage handling(scaling down) the larger images.
Have a look at my question:
Strange crash drawing on canvas on Android 4.0.3. A/libc: Fatal signal 11 (SIGSEGV)
maybe it's the same problem. The issue arises when I try to use a small number for stroke or others Paint properties.
setStrokeWidth(0.007f);
Never solved, I suggest to scale the Canvas and use bigger numbers.
I have one Activity and 4 tab Activities.In each tab activity i have gallery , grid layout when i am coming back from tab-activities to my main Activity i am getting outofMemory exception.In my all tab activities i have lot of images.I have strucked from 5 day .Please help me.Here my logcat is:
07-30 17:28:42.375: I/dalvikvm-heap(18784): Forcing collection of SoftReferences for 16384016-byte allocation
07-30 17:28:42.406: D/dalvikvm(18784): GC_BEFORE_OOM freed 1K, 34% free 40614K/61511K, paused 29ms, total 30ms
07-30 17:28:42.406:
E/dalvikvm-heap(18784): Out of memory on a 16384016-byte allocation.
07-30 17:28:42.406: I/dalvikvm(18784): "main" prio=5 tid=1 RUNNABLE
07-30 17:28:42.406: I/dalvikvm(18784):
| group="main" sCount=0 dsCount=0 obj=0x41f726a0 self=0x41f5f018
07-30 17:28:42.406: I/dalvikvm(18784):
| sysTid=18784 nice=0 sched=0/0 cgrp=apps handle=1075198032
07-30 17:28:42.406: I/dalvikvm(18784):
| schedstat=( 0 0 0 ) utm=219 stm=55 core=0
07-30 17:28:42.406: I/dalvikvm(18784):
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
07-30 17:28:42.406: I/dalvikvm(18784):
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:592)
07-30 17:28:42.406: I/dalvikvm(18784):
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:445)
07-30 17:28:42.406: I/dalvikvm(18784):
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
07-30 17:28:42.406:
I/dalvikvm(18784): at android.content.res.Resources.loadDrawable(Resources.java:1963)
07-30 17:28:42.406:
I/dalvikvm(18784): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.View.<init>(View.java:3419)
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.View.<init>(View.java:3352)
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.ViewGroup.<init>(ViewGroup.java:426)
07-30 17:28:42.406: I/dalvikvm(18784): at android.widget.RelativeLayout.<init>(RelativeLayout.java:184)
07-30 17:28:42.406: I/dalvikvm(18784): at java.lang.reflect.Constructor.constructNative(Native Method)
07-30 17:28:42.406: I/dalvikvm(18784): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.LayoutInflater.createView(LayoutInflater.java:587)
07-30 17:28:42.406: I/dalvikvm(18784): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
07-30 17:28:42.406: I/dalvikvm(18784): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
07-30 17:28:42.416: I/dalvikvm(18784): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
07-30 17:28:42.416: I/dalvikvm(18784): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-30 17:28:42.416: I/dalvikvm(18784): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-30 17:28:42.416: I/dalvikvm(18784): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:306)
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.Activity.setContentView(Activity.java:1901)
07-30 17:28:42.416: I/dalvikvm(18784): at com.inventit.commentu.CommentU_Activity.onCreate(CommentU_Activity.java:182)
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.Activity.performCreate(Activity.java:5048)
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2052)
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread.access$700(ActivityThread.java:139)
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
07-30 17:28:42.416: I/dalvikvm(18784): at android.os.Handler.dispatchMessage(Handler.java:99)
07-30 17:28:42.416: I/dalvikvm(18784): at android.os.Looper.loop(Looper.java:137)
07-30 17:28:42.416: I/dalvikvm(18784): at android.app.ActivityThread.main(ActivityThread.java:4918)
07-30 17:28:42.416: I/dalvikvm(18784): at java.lang.reflect.Method.invokeNative(Native Method)
07-30 17:28:42.416: I/dalvikvm(18784): at java.lang.reflect.Method.invoke(Method.java:511)
07-30 17:28:42.416: I/dalvikvm(18784): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
07-30 17:28:42.416: I/dalvikvm(18784): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
07-30 17:28:42.416: I/dalvikvm(18784): at dalvik.system.NativeStart.main(Native Method)
07-30 17:28:42.416: A/libc(18784): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 18784 (ventit.commentu)
07-30 17:28:42.416: A/libc(18784): Fatal signal 11 (SIGSEGV) at 0x007d0000 (code=1), thread 18799 (ventit.commentu)
07-30 17:28:50.154: E/Trace(18971): error opening trace file: No such file or directory (2)
07-30 17:28:50.154: D/ActivityThread(18971): setTargetHeapUtilization:0.25
07-30 17:28:50.154: D/ActivityThread(18971): setTargetHeapIdealFree:8388608
07-30 17:28:50.154: D/ActivityThread(18971): setTargetHeapConcurrentStart:2097152
07-30 17:28:50.294: D/dalvikvm(18971): GC_FOR_ALLOC freed 76K, 23% free 16129K/20931K, paused 16ms, total 17ms
07-30 17:28:50.334: I/dalvikvm-heap(18971): Grow heap (frag case) to 40.043MB for 16384016-byte allocation
Thanking in Advance.
Check the Managing Bitmap Memory article from developers site.
For API<=10:
On Android 2.3.3 (API level 10) and lower, using recycle() is recommended. If you're displaying large amounts of bitmap data in your app, you're likely to run into OutOfMemoryError errors. The recycle() method allows an app to reclaim memory as soon as possible.
Caution: You should use recycle() only when you are sure that the bitmap is no longer being used. If you call recycle() and later attempt to draw the bitmap, you will get the error: "Canvas: trying to use a recycled bitmap".
The following code snippet gives an example of calling recycle(). It uses reference counting (in the variables mDisplayRefCount and mCacheRefCount) to track whether a bitmap is currently being displayed or in the cache. The code recycles the bitmap when these conditions are met:
The reference count for both mDisplayRefCount and mCacheRefCount is 0.
The bitmap is not null, and it hasn't been recycled yet.
For API>=11:
Android 3.0 (API Level 11) introduces the BitmapFactory.Options.inBitmap field. If this option is set, decode methods that take the Options object will attempt to reuse an existing bitmap when loading content. This means that the bitmap's memory is reused, resulting in improved performance, and removing both memory allocation and de-allocation.
on click opening a dialog view it giving an out of memory? In dialog i have two images in it and 1 image button, even the size of image is 40 50kb.
04-15 10:11:07.085: E/dalvikvm-heap(29896): Out of memory on a 16384016-byte allocation.
04-15 10:11:07.085: I/dalvikvm(29896): "main" prio=5 tid=1 RUNNABLE
04-15 10:11:07.085: I/dalvikvm(29896): | group="main" sCount=0 dsCount=0 obj=0x40c51460 self=0x12938
04-15 10:11:07.085: I/dalvikvm(29896): | sysTid=29896 nice=0 sched=0/0 cgrp=default handle=1075008808
04-15 10:11:07.085: I/dalvikvm(29896): | schedstat=( 1269958584 831219251 1666 ) utm=105 stm=21 core=0
04-15 10:11:07.085: I/dalvikvm(29896): at android.graphics.Bitmap.nativeCreate(Native Method)
04-15 10:11:07.090: I/dalvikvm(29896): at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
04-15 10:11:07.090: I/dalvikvm(29896): at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
04-15 10:11:07.090: I/dalvikvm(29896): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
04-15 10:11:07.090: I/dalvikvm(29896): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:618)
04-15 10:11:07.090: I/dalvikvm(29896): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:593)
04-15 10:11:07.090: I/dalvikvm(29896): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:445)
04-15 10:11:07.090: I/dalvikvm(29896): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
04-15 10:11:07.090: I/dalvikvm(29896): at android.content.res.Resources.loadDrawable(Resources.java:1968)
04-15 10:11:07.090: I/dalvikvm(29896): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-15 10:11:07.095: I/dalvikvm(29896): at android.widget.ImageView.<init>(ImageView.java:119)
04-15 10:11:07.095: I/dalvikvm(29896): at android.widget.ImageView.<init>(ImageView.java:109)
04-15 10:11:07.095: I/dalvikvm(29896): at java.lang.reflect.Constructor.constructNative(Native Method)
04-15 10:11:07.095: I/dalvikvm(29896): at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-15 10:11:07.095: I/dalvikvm(29896): at android.view.LayoutInflater.createView(LayoutInflater.java:586)
04-15 10:11:07.100: I/dalvikvm(29896): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-15 10:11:07.100: I/dalvikvm(29896): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
04-15 10:11:07.100: I/dalvikvm(29896): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)