LifeCycle of an Activity

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

LifeCycle of an Activity

Postby plusminus » Thu Nov 22, 2007 3:06 pm

[align=center]The Activity-LifeCycle

:warning: since SDK v0.9 the neming of the "states" is a bit different, however the overall 'way' is the same :warning:
@Source

If you have problems understanding or other questions, post right below...

Image[/align]

Regards,
plusminus
Last edited by plusminus on Tue Sep 16, 2008 2:10 pm, edited 3 times in total.
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Examples?

Postby Spoogle » Mon Dec 10, 2007 3:16 pm

Could someone elaborate a little bit with examples of how these might get used? This kind of lifecycle is a little bit new to me...and having 8 stages complicates things a little bit (onStart and onStop would be straightforward...onCreate onStart onResume etc. starts to get a little hairy...)

Could someone give some examples in which all of these get used? Or just a few examples that collectively use all of them? I'm just trying to wrap my brain around what questions I need to ask myself when writing an Android app to implement the lifecycle. Thanks in advance!
Spoogle
Freshman
Freshman
 
Posts: 5
Joined: Mon Nov 26, 2007 3:50 pm

Re: Examples?

Postby jackdesu » Fri Dec 14, 2007 8:20 am

Hi
I suggest you might implement all callback functions of life cycle:

onCreate(), onStart(), onResume(), onFreeze(), onPause(), onStop() and onDestroy().

Set breakpoint for each callback functions and start the activity with eclipse debugger.
Then you could operate some actions on that activity, see how state life state goes.
jackdesu
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Dec 14, 2007 7:35 am

Postby tum0rc0re » Sat Dec 15, 2007 7:16 am

I wrote new article (+ tutorial) about an essence of Activity. There's an explanation of return some value from Activity in the tutotial. Article wrote on russian language :) Here you can look it and download source code of tutorial - http://www.maximyudin.com/?p=12
User avatar
tum0rc0re
Senior Developer
Senior Developer
 
Posts: 158
Joined: Sun Nov 25, 2007 7:15 am
Location: Moscow, Russia

Postby Ghalya » Sat Feb 09, 2008 4:14 pm

Thanks mr. plusmius for ur digram, it help me alot ^^
Ghalya
Freshman
Freshman
 
Posts: 9
Joined: Sat Feb 09, 2008 4:07 pm
Location: Dubai, UAE

Postby plusminus » Sat Feb 09, 2008 4:19 pm

Ghalya wrote:Thanks mr. plusmius for ur digram, it help me alot ^^


Its the original one from Google :) but obviously seems a bit hidden .)

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby wilken » Fri Oct 17, 2008 8:38 am

hi all,
picking up on the lifecycle question, can anybody explain to me when onSaveInstanceState is called?

i have a test activity that implements onSaveInstanceState, but it is never called, and consequently the bundle in oncreate is always null.

what i do is:

start application
- onCreate
- onStart
- onResume

press back
- onPause
- onStop
- onDestroy

(no onSaveInstanceState called)

start again
- onCreate
- onStart
- onResume

press home
- onPause
- onStop

(no onSaveInstanceState called)

if onSaveInstanceState is not called in any of these instances, when is it called?
wilken
Developer
Developer
 
Posts: 35
Joined: Wed Oct 08, 2008 8:22 am

Postby MrSnowflake » Mon Nov 03, 2008 11:23 pm

onSaveInstanceState() is called when a configuration change happens. That means: "Unless you specify otherwise, a configuration change (such as a change in screen orientation, language, input devices, etc) will cause your current activity to be destroyed, going through the normal activity lifecycle process of onPause(), onStop(), and onDestroy() as appropriate. If the activity had been in the foreground or visible to the user, once onDestroy() is called in that instance then a new instance of the activity will be created, with whatever savedInstanceState the previous instance had generated from onSaveInstanceState(Bundle)." (From the docs).
User avatar
MrSnowflake
Moderator
Moderator
 
Posts: 1439
Joined: Sat Feb 16, 2008 3:11 pm
Location: Flanders, Belgium

Postby meojunior » Tue Jan 20, 2009 11:46 am

Hi all,

here is video illustrator about life cycle of andorid apps, you can get source code by svn:
http://blip.tv/file/958450/

more detail:
http://sleepydroid.blogspot.com/

Regard,
meojunior
User avatar
meojunior
Freshman
Freshman
 
Posts: 4
Joined: Mon Jan 05, 2009 4:16 am
Location: VietNam

Life cycle Activity

Postby desuvinodkumar » Tue Mar 24, 2009 8:34 am

thnxs
Last edited by desuvinodkumar on Fri Mar 05, 2010 8:28 am, edited 1 time in total.
Vinod...
User avatar
desuvinodkumar
Senior Developer
Senior Developer
 
Posts: 102
Joined: Mon Mar 23, 2009 6:51 am
Location: India

lifecycle of Activity

Postby nishi1607 » Mon Jul 20, 2009 1:08 pm

CAn anyone explain,who manages the lifecycle of Activity,
as in J2me AMS is there,
once we run the activity,
who calls the instance of activity and how it initializes the Activity
nishi1607
Once Poster
Once Poster
 
Posts: 1
Joined: Mon May 04, 2009 8:01 am

Postby spring » Fri Mar 05, 2010 7:47 am

there is a tutorial illustrate the life cycle in activity from developer.android.com

see this:http://developer.android.com/resources/tutorials/notepad/index.html
spring
Junior Developer
Junior Developer
 
Posts: 19
Joined: Sat Jan 09, 2010 4:37 am
Location: China

Re: LifeCycle of an Activity

Postby inzhangbarbor » Fri Jul 02, 2010 3:13 pm

Here is the official explanation from Google. Most of this information is already posted, but here is the link http://developer.android.com/reference/ ... ivity.html
inzhangbarbor
Freshman
Freshman
 
Posts: 4
Joined: Fri Jul 02, 2010 3:01 pm

Re: LifeCycle of an Activity

Postby jupiterjones7 » Fri Oct 22, 2010 4:13 pm

Thank you for all videos and pictures! I've just started and now i've finally understood lifecycles!!
"Happiness is only real when shared" - Chris McCandless
User avatar
jupiterjones7
Freshman
Freshman
 
Posts: 7
Joined: Fri Oct 22, 2010 2:31 pm

Re: LifeCycle of an Activity

Postby millerni456 » Tue Oct 25, 2011 8:17 pm

If I do not take care to clean up properly, is it possible that my code will create multiple instances of certain objects? I'm having a problem where the application will progressively get slower each time you run it.
millerni456
Junior Developer
Junior Developer
 
Posts: 12
Joined: Wed Oct 05, 2011 12:39 am

Top
Next

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests