Re: [android-developers] OutOfMemory exception in OnCreate

2010-10-02 Thread Prakash Iyer
On Sat, Oct 2, 2010 at 6:14 PM, Yahel  wrote:

> Hi all,
>
> I'm having a hard time resolving a crash report.
> It's an OutOfMemory exception that occurs during the setContentView in
> the onCreate of my main activity.
>
> I just want to be sure I understood Android LifeCycle well :
>
> 1) The onCreate of my main activity is called once and only once
> during the life time of my application ? Is that correct ?
>

If what you mean is the process, then your answer is a no. Assuming this is
an Activity that can be launched from the launcher, i.e. no other Intent, a
process will be spawned the first time the user decides to start your
Activity. Then it goes through the lifecycle as described quite well in the
Activity documentation. Thus it is quite likely that onCreate gets called
multiple times, e.g. if you have not over-ridden the orientation change, it
will get called whenever the phone moves from landscape to portrait or vice
versa. You can test this out quite easily on the emulator.

Thus, if you have static variables etc. they will live thru all of this.
Your view will be cleaned up and redone in the onCreate.


> 2) Just like for the big bang, before the oncreate of my activity,
> nothing exists for that activity, so memory consumption is zero, no
> objects exists right ?
>

Not correct. onCreate is called on an instance, so all the static variables
and any thing else required by your instance, e.g. a String that you may
have defined as a member variable etc is already loaded. Maybe you knew that
and are asking something else??



> So what can cause that sometimes, with random framework and devices, I
> get an OOM exception ?
> I mean if say my background image  is causing this, it should blow up
> everytime, on every device, shouldn't it ? I mean the result should be
> reliable.
>
> The background image is a standard jpg : 360*480 weighing 37kb,
> nothing fancy really :s
>

I think more detail here will help, Is this a bitmap loaded into a variable?
If yes and you hold a reference to your Activity object elsewhere, you might
leak for every orientation change.
...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] OutOfMemory exception in OnCreate

2010-10-02 Thread Yahel
Hi all,

I'm having a hard time resolving a crash report.
It's an OutOfMemory exception that occurs during the setContentView in
the onCreate of my main activity.

I just want to be sure I understood Android LifeCycle well :

1) The onCreate of my main activity is called once and only once
during the life time of my application ? Is that correct ?

2) Just like for the big bang, before the oncreate of my activity,
nothing exists for that activity, so memory consumption is zero, no
objects exists right ?

So what can cause that sometimes, with random framework and devices, I
get an OOM exception ?
I mean if say my background image  is causing this, it should blow up
everytime, on every device, shouldn't it ? I mean the result should be
reliable.

The background image is a standard jpg : 360*480 weighing 37kb,
nothing fancy really :s

The crash report below :

java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.kayenko.awof/com.kayenko.awof.Main}:
android.view.InflateException: Binary XML file line #10: Error
inflating class 
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2663)
at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:
2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #10:
Error inflating class 
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at
com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:
56)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:
563)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:
198)
at android.app.Activity.setContentView(Activity.java:1647)

at com.kayenko.awof.Main.onCreate(Main.java:174)

at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2627)
... 11 more
Caused by: java.lang.reflect.InvocationTargetException
at android.widget.FrameLayout.(FrameLayout.java:79)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 22 more
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
at android.graphics.Bitmap.createBitmap(Bitmap.java:435)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:340)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:
488)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:
462)
at
android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:
323)
at
android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:
697)
at android.content.res.Resources.loadDrawable(Resources.java:1709)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.view.View.(View.java:1885)
at android.view.ViewGroup.(ViewGroup.java:291)
at android.widget.FrameLayout.(FrameLayout.java:83)
... 26 more


Thanks for any hint.

Yahel
http://www.a-world-of-faces

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en