This example describes an activity lifecycle based on the log demo of Android programming. Share to everyone for your reference, specific as follows:
Use the Android log to demonstrate the lifecycle of an activity
Code:
Demoactivity.java package uni.activity; /* @author Octobershiner 7 SE.
HIT * * Import android.app.Activity;
Import Android.os.Bundle;
Import Android.util.Log; The public class Activitydemoactivity extends activity {/** called the ' when ' is the ' The activity ' is the ' the './private static
Final String TAG = "Demo";
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
LOG.D ("Demo", "This is a test string");
} protected void OnStart () {Super.onstart ();
LOG.I (TAG, "the activity state---->onstart");
} protected void Onrestart () {Super.onrestart ();
LOG.I (TAG, "the activity state---->onreatart");
} protected void Onresume () {super.onresume ();
LOG.I (TAG, "the activity state---->onresume");
} protected void OnPause () {super.onpause ();
LOG.I (TAG, "the activity state---->onpause");
} protected void OnStop () {super.onstop (); LOG.I (TAG, "the activity State---->onstop ");
} protected void OnDestroy () {Super.ondestroy ();
LOG.I (TAG, "the activity state---->ondestroy");
}
}
This is the result of the demo
Use log to show life cycle of activity
Note indicates that the action performed in the middle is a convenient observation, and you can click the plus sign on the right side of the Logcat window (which is not available in Show view in the Window menu) to create a filter, and my example filters the demo
/start running demo 07-22 11:18:19.311:info/demo (281): The activity state---->onstart 07-22 11:18:19.311:info/demo (281): The activity state---->onresume///press the back key to return the activity from the stack by popping 07-22 11:18:34.821:
Info/demo (281): The activity state---->onpause 07-22 11:18:35.090:info/demo (281): The Activity State---->onstop 07-22 11:18:35.090:info/demo (281): The activity state---->ondestroy//Restart demo 07-22 11:18:45.550:info/demo (281): The activity state---->onstart 07-22 11:18:45.550:info/demo (281): The activity state---->onresume//pressed the home key The current task is in the background, and the system saves state 07-22 11:18:53.750:info/demo (281): The---->onpause 07-22 11:18:54.820:info/demo (281): The activity state---->onstop//Restart demo back to the original task activity at the top of the stack 07-22 11:19:03.550:info/demo (281): The activity State---->onreatart 07-22 11:19:03.550:info/demo (281): the---->onstart 07-22 Demo (281): The activity state---->onresume
Also filter the way to view log:
Instance
Copy Code code as follows:
LOG.I ("Yourdemo", "This are My Log");
A friend who doesn't have a logcat window can pull up a window in Show view in the Window menu
Five circles can filter five different logs, respectively.
Notice the green plus sign on the right, click to customize your own filter, and the name will be fine.
By log tag to select the filter you want to create the rules, such as you want to filter out the encounter tag labeled "Yourdemo" Log, you can enter Yourdemo in the
I hope this article will help you with the Android program.