Life Cycle of Activity – Flow of Android Application

lifecycle

Android Application has a unique and very easy workflow what does it mean that , whenever a developer develops a android application. He has to follow the work Flow of android application.Whenever we extend Activity in our Java file it imports android.app.activity class

How Activity of an android application transit between one Activity to another Activity.Lets explore –

As we can see the below diagram according to http://developer.android.com/  , Activity life cyle has 7 main methods in which our Activity is transit within.

lifecycle of activity

Let’s take a glance of Activity life cycle and understand how it works- Simple definition and implementations-

1) . onCreate() –  This method calls whenever Activity is first created. This is First method invoked in which we do our coding like setContentView(R.layout.activity_main).

2). onStart() – This method is called when Activity is becoming visible to user and eventually user is able to see the App , as you can see the Activity image above . onCreate immediately calls onStart().

3). onResume() – This method is invoked after onStart() method , It called whenever activity is interacting with the users continuously .

4). onPause() – This method is invoked whenever Activity goes in Pause state like during music if call comes then music player goes in pause state.

5). onStop() – This method is invoked when Activity is no longer interacting with the user.

6). onRestart() – This Activity invoked whenever after Activity is stopped and priority is to start.

7). onDestroy() – This methods invoked whenever our Activity is destroyed .User exit the Application.

According to official website of android i.e http://developer.android.com/training/basics/activity-lifecycle/index.html example of Activitylife cycle  .This source code you can download

Download code

Output –

activity_output_1

activity2

activity3

dialog

 

for more query and suggestions do post here :p Happy coding folks!

 

  • Anurag

    Nice tutorial… (y)

  • @disqus_apToXS50un:disqus Thank You Anurag Keep visting our new tuts 🙂

  • Arjun pal

    Very helpful, easy and understandable 🙂

  • Gurleen Singh

    nice one , (y)