How to define multiple activity in an application
-Define a class that inherits activity
-Carbon oncreate ()
Setcontentview (r.layout.secondlayout): Sets the layout file used by the activity
-Register the activity in the Androidmanifest.xml file
1) Add an activity tag in the application tag, name is usually "package name + class name", label is usually the activity name
2) If you want to modify the activity that the program starts by default, you need to move the intent-filter tag and its contents into the activity
Second, the way to start an activity
-Generate an Intent object (Intent)
Intent Intent = new Intent ();
-Call the SetClass method to set the activity requested to start
Intent.setclass (Mainactivity.this,secondactivity.class);
The first parameter of the SetClass function is a context object
Context is a class in which activity is a subclass of the context class, meaning that all activity objects can be transformed upward into a context object
The second parameter is a class object, which should pass in the class object of the activity that needs to be started in the current scene
-Invoke the StartActivity method to start activity
StartActivity (Intent);
Third, the back stack in Android
The activated activity is placed in a stack, called the back stack.
Iv. life cycle function of activity
-oncreate, called the first time the activity is created
-onstart, called when activity becomes visible
-onresume, called when activity starts preparing to interact with the user
-onpause, called when the system is about to start another activity
-onstop, called when the current activity becomes invisible
-ondestroy, called before the current activity is destroyed
-onrestart, called when an activity is started again
V. Status of the Activity object
-resumed,activity object is in the running state
-paused, another activity is on the front, but this activity is still visible
-stopped, another activity on the front end that completely obscures the activity
Six, paired life cycle functions
Onpause<-->onresume
Onstop<-->onstart
Oncreate<-->ondestroy
Onrestart
Seven, take driving as an example
oncreate--> Buy a car
Ondestroy--> Car Scrap
Onstart--> Ignition
onstop--> stall
Onresume--> on the accelerator, driving the car forward
Onpause-->, loosen the throttle.
Android Learning Note (10) life cycle of activity