android examples_ activity life cycle example in android
TRANSCRIPT
-
7/29/2019 Android Examples_ Activity Life Cycle Example in Android
1/5
android examples
WEDNESDAY, JULY 27, 2011
Activity Life Cycle Example In Android
Activity Life Cycle ::
Below shows the methods of Activity
a)onCreate()
b)onStart()
c)onPause()
d)onResume()
e)onStop()
f) onDestroy()
The above figure shows how and when activity is created and when it is pausedand destroyed.
means when the resources are low OS will kill the activity.
onCreate() ::This method is called when first time activity is created.
onStart()::This method is called just before your activity becomes visible on the
screen.
onResume()::This method is called after onStart() method and if your activity is
the foreground activity on the screen.
onPause()::This method is called when your activity is just about to call another
activity so that the current activity has to be paused and the new activity has to be
resumed. Here the previous activity is not stopped but it loss the foreground
Join this site
w ith Google Friend Connect
Members (9)
Already a member? Sign in
FOLLOWERS
2011 (6)
July (1)
Activity Life Cycle ExampleIn Android
June (5)
BLOG ARCHIVE
manikanta
I always try to make my friends
smile.
View my complete profile
ABOUT ME
1Share More Next Blog Create Blog Sign
http://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://www.blogger.com/http://www.blogger.com/http://www.blogger.com/home#createhttp://www.blogger.com/next-blog?navBar=true&blogID=4157633083686631670http://www.blogger.com/profile/05850610804805143704http://www.blogger.com/profile/05850610804805143704http://manisivapuram.blogspot.in/2011_06_01_archive.htmlhttp://void%280%29/http://manisivapuram.blogspot.in/2011/07/activity-life-cycle-example.htmlhttp://manisivapuram.blogspot.in/2011_07_01_archive.htmlhttp://void%280%29/http://manisivapuram.blogspot.in/search?updated-min=2011-01-01T00:00:00-08:00&updated-max=2012-01-01T00:00:00-08:00&max-results=6http://void%280%29/http://3.bp.blogspot.com/-HcAyAD7diac/TjD5Ek5s6uI/AAAAAAAAACM/TIKWhm6K38E/s1600/ActiviyLifeCycle.bmphttp://manisivapuram.blogspot.in/ -
7/29/2019 Android Examples_ Activity Life Cycle Example in Android
2/5
visibility means it goes as background activity.
onStop()::This method is called when your activity is no longer visible on the
screen.
onDestroy()::This method is called when your current activity has the last
chance to do any processing before it is destroyed.
Activity Life Cycle Example ::
Create a new project with the name BasicActivityExample and create a class
with the name LifeCycleActivity as a main activity.
// LifeCycleActivity.java
package com.android.tutorial;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;
publicclass LifeCycleActivity extends Activity {
/** Called when the activity is first created. */
@Override
publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Toast.makeText(this, "onCreate()",
Toast.LENGTH_LONG).show();
}
@Override
protectedvoid onStart() {
//the activity is become visible.
super.onStart();
Toast.makeText(this, "onStart()",
Toast.LENGTH_LONG).show();
}
@Override
protectedvoid onPause() {
http://4.bp.blogspot.com/-zrQDE-r03zk/TjD6ty6_MuI/AAAAAAAAACQ/PDjJsqf39b0/s1600/BasicActivityProjectFlow.bmp -
7/29/2019 Android Examples_ Activity Life Cycle Example in Android
3/5
super.onPause();
Toast.makeText(this, "onPause()",
Toast.LENGTH_LONG).show();
}
@Override
protectedvoid onResume() {
// TODO Auto-generated method stub
super.onResume();
Toast.makeText(this, "onResume()",
Toast.LENGTH_LONG).show();
}
@Override
protectedvoid onStop() {
//the activity is no longer visible.
super.onStop();
Toast.makeText(this, "onStop()", Toast.LENGTH_LONG).show();
}
@Override
protectedvoid onDestroy() {
//The activity about to be destroyed.
super.onDestroy();
Toast.makeText(this, "onDestroy()",
Toast.LENGTH_LONG).show();
}
}
In the above program we wrote all the Life Cycle Methods. Here
Toast.makeText(...) method is used to display the text on the screen.
//main.xml
The above program is the best and simple example how the activity methods will
execute one by one.Remember when the application is started see the bottom it
-
7/29/2019 Android Examples_ Activity Life Cycle Example in Android
4/5
Older PostHome
Subscribe to: Post Comments (Atom)
Posted by manikanta at 11:10 PM
display's which methods are exeuted when an an activity is running.
After all the few seconds click on ESC in the keyboard or press back button in
your emulator then you may see the methods which are executed when an
application is destroyed.
PLEASE LET ME KNOW IF U ARE FACING ANY PROBLEMS WITH THIS
APPLICATION AND U NEED TO KNOW MORE INFORMATION REGARDING
THIS ACTIVITY LIFE CYCLE PLEASE COMMENT IT.
+1 Recommend this on Google
Enter your comment...
Comment as: Google Account
Publish Preview
3 comments:
Venkateswara Reddy July 15, 2012 at 4:06 AM
hi,this information is good ,for a beginner but it should be in more clarity.
Reply
Venkata Reddy Nallamilli November 1, 2012 at 11:37 PM
ok good.but try to give the example with more Activities.
by using that we can understand more about the lifecycle phases...
Reply
Thulasiram December 11, 2012 at 2:02 AM
Reply
http://manisivapuram.blogspot.com/2011/07/activity-life-cycle-example.html?showComment=1355220156894#c4337310202781203419http://www.blogger.com/profile/17310821824166557868http://manisivapuram.blogspot.com/2011/07/activity-life-cycle-example.html?showComment=1351838235426#c741218683982834908http://www.blogger.com/profile/05802906433757825442http://manisivapuram.blogspot.com/2011/07/activity-life-cycle-example.html?showComment=1342350374616#c1845499113705906583http://www.blogger.com/profile/09033049237133866575http://www.blogger.com/share-post.g?blogID=4157633083686631670&postID=4543012447913094203&target=facebookhttp://www.blogger.com/share-post.g?blogID=4157633083686631670&postID=4543012447913094203&target=twitterhttp://www.blogger.com/share-post.g?blogID=4157633083686631670&postID=4543012447913094203&target=bloghttp://www.blogger.com/share-post.g?blogID=4157633083686631670&postID=4543012447913094203&target=emailhttp://manisivapuram.blogspot.in/2011/07/activity-life-cycle-example.htmlhttp://www.blogger.com/profile/05850610804805143704http://manisivapuram.blogspot.com/feeds/4543012447913094203/comments/defaulthttp://manisivapuram.blogspot.in/http://manisivapuram.blogspot.in/2011/06/slideshow-of-images-using-android.html -
7/29/2019 Android Examples_ Activity Life Cycle Example in Android
5/5
Picture Window template. Powered by Blogger.
http://www.blogger.com/