Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By kjkrum

Thread: What Happens inside each ativity Lifecycle call back method?

  1. #1
    Nazneen Ali is offline Senior Member
    Join Date
    Jul 2011
    Posts
    112
    Rep Power
    0

    Default What Happens inside each ativity Lifecycle call back method?

    I am a beginner to learning android development. I have summarized what I have read about and learnt about the life cycle of an activity and its call back methods, as follows. I want some people to kindly evaluate and correct me where I am wrong, and feel free to add anything which happens and we can do inside these methods, as ANSWERS to this post or COMMENTS (Please keep it simple if you add something since i am a beginner and anything complex will confuse me.) Thank you in advance.
    onCreate(Bundle savedState)

    • If being created for the first time, the bundle passed in is NULL. In such a case,
    • Normal Static Setup
    • Collecting GUI resources
    • If being created after it was destroyed, restores state from the Bundle passed in.

    onStart()

    • Draw GUI using collected resources, so the GUI becomes visible

    onResume()

    • Get any system resources released in onPause(), if following onPause()



    • GUI starts working, e.g. user input taken, animations playing etc.

    onPause()

    • Release system resources consuming objects e.g. network connections, camera etc.
    • Suspend animations and similar on-going actions

    onStop()

    • Activity instance's current state saved in the system managed Bundle object by calling onSaveInstanceState()
    • Variables and GUI resources are lost

    onRestart()

    • GUI resources are gathered again

    onDestroy()

    • Nothing is saved
    • Everything is lost
    • The activity will have to be recreated when the user visits it again.
    Don't forget to smile :-)

  2. #2
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,060
    Rep Power
    6

    Default Re: What Happens inside each ativity Lifecycle call back method?

    There are actually more lifecycle methods than these, but you will probably never need to use them. The most important ones are onCreate(), onResume(), and onPause(). What you noted about the bundle is important. Activities in the back stack are quite often destroyed and re-created, so you must not assume that onCreate() is always creating a new activity from the user's perspective. You're also correct that resources should be obtained in onResume() and released in onPause(). This is because there is no guarantee that anything after onPause() will ever be called. If a resource needs to remain open through multiple activities, let it be managed by a Service and have each Activity bind/unbind the Service in onResume()/onPause(). Avoid the simpler technique of putting global state in your Application. If your app ever starts a Service in its own process, it will run with its own copy of the Application.
    Nazneen Ali likes this.
    Get in the habit of using standard Java naming conventions!

  3. #3
    Nazneen Ali is offline Senior Member
    Join Date
    Jul 2011
    Posts
    112
    Rep Power
    0

    Default Re: What Happens inside each ativity Lifecycle call back method?

    Thank you so very much !
    Don't forget to smile :-)

Similar Threads

  1. Lifecycle of objects created inside a function?
    By petzeee in forum New To Java
    Replies: 2
    Last Post: 01-25-2013, 10:22 AM
  2. Call .NET method inside Java
    By kishorkna in forum New To Java
    Replies: 0
    Last Post: 10-10-2011, 07:47 AM
  3. Unable to call paint() from inside method
    By Y. Progammer in forum New To Java
    Replies: 3
    Last Post: 03-01-2010, 01:47 PM
  4. how to call service method inside another service
    By kirtichopra2003 in forum Web Frameworks
    Replies: 1
    Last Post: 10-24-2009, 03:19 AM
  5. How to call JSP inside Servlet
    By Swamipsn in forum Advanced Java
    Replies: 0
    Last Post: 07-31-2007, 01:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •