Users Online

· Guests Online: 133

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

003 Java Andorid Program to Demonstrate Activity Life Cycle

















































An Activity in android application can take these states
1.Created – Activity is created
2.Running – Activity is visible and interacts with the user
3.Paused -Activity is still visible but partially obscured, instance is running but might be killed by the system.
4.Stopped – Activity is not visible, instance is running but might be killed by the system.
5.Destroyed -Activity has been terminated by the system of by a call to its finish() method.
When an activity is first created its onCreate() method gets called then if the subsequent onStart() method gets called and then the activity proceeds to its onResume() method it here where the activity starts to run , now another activity can come into foreground which forces this app to go into a paused state , now either this activity can get killed by the os or get resumed or the activity calls its onStop() method where the activity now goes into its Ondestroy() method and get killed.
For more info go to – http://developer.android.com/training/basics/activity-lifecycle/starting.html

The following code demonstartes the above procedure.

Main Activity




package com.example.activity_life;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

@SuppressLint("NewApi")
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
notify("onCreate");
}

@Override
protected void onPause() {
super.onPause();
notify("onPause");
}

@Override
protected void onResume() {
super.onResume();
notify("onResume");
}

@Override
protected void onStop() {
super.onStop();
notify("onStop");
}

@Override
protected void onDestroy() {
super.onDestroy();
notify("onDestroy");
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
notify("onRestoreInstanceState");
}

@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
notify("onSaveInstanceState");
}

private void notify(String methodName) {
String name = this.getClass().getName();
String[] strings = name.split("\\.");
Toast.makeText(getApplicationContext(),
methodName + "" + strings[strings.length - 1],
Toast.LENGTH_LONG).show();
}

}









Comments

2 #1 divya
on December 03 2015 15:09:11
Excellent article on Activiy Life CycleSmile
50 #2 Anil_Pogula
on March 17 2016 03:29:10
Good article on Activity Life Cycle

Guttitech Solutions also provides courses on Mobile applications along with projects.... and a platform of Q&A to practice on the respective topics ... which will prepare the member thoroughly on the subject.. Excellent...SmileSmileSmile

Thanks Guttitech

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

Awesome! Awesome! 0% [No Votes]
Very Good Very Good 100% [1 Vote]
Good Good 0% [No Votes]
Average Average 0% [No Votes]
Poor Poor 0% [No Votes]
Render time: 0.87 seconds
10,810,283 unique visits