Saturday, October 2, 2010

[android-developers] Re: OutOfMemory exception in OnCreate

Thank you for your answer.

So now I understand that the onCreate method can be called several
time, for example on orientation change.

My app is set to Portrait mode only using manifest's
android:screenOrientation="portrait" so I don't expect any orientation
change in the app.

Could there be any other obvious reason for the activity to be
reinstanciated, therefore triggering the onCreate method again ?

My app does only startActivityForResult and a Share Intent nothing
more than that.

But that must be what happens, I'm going to reread thoroughfully the
Activity documentation and try to cleanup and save only what's needed
in the onDestroy method.

Thanks again.

Yahel

On 3 oct, 00:32, Prakash Iyer <thei...@gmail.com> wrote:
> On Sat, Oct 2, 2010 at 6:14 PM, Yahel <kaye...@gmail.com> 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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate