Will register Activity in the project manifest file
Will be set to start Activity in the project manifest file
One, the role of Activity
Activity is one of the four core components of Android. Its main function is to provide an interface and interact with users.
A program is generally composed of multiple activities, the relationship between each activity is very loose, there is no direct relationship between them. There must be an activity designated as the main activity, which is the first interface displayed when the program starts. Each activity can start other activities at will. Whenever an activity is started, the previous activity is stopped. All started activities in a program are placed in a stack, so the stopped activity is not destroyed, but stored in the stack. The newly started activity is first stored in the stack and then gets the input focus. Click the return button on the currently active activity, it is removed from the stack, and then destroyed, and then the previous activity is restored.
When an activity is stopped because a new activity is started, it will be notified of a state change. There are multiple such changes, each of which will cause the system to call a corresponding callback method to notify the activity. These callback methods are collectively referred to as "Life cycle callback method". These callback methods are called when the Activity is created, stopped, resumed, and destroyed.
Two, create a custom Activity
Create Android application [ActivityOverview]
1. Create based on common class inheriting Activity
New Java class
Enter the class name
Add documentation comments to the class
Create a layout file activity_login for LoginActivity as the user interface
Set the layout file name-activity_login
Switch to Code view
Set linear layout attributes, add a label, set attributes
Modify LoginActivity, inherit AppCompatActivity
Create a callback method onCreate(), use the layout resource file to set the user interface
2. Created based on the Activity template of Android Studio
Create a custom activity based on the Empty Activity template
Configure Activity information
Add a label control to the layout file
Three, register a custom Activity
1. View the project list file
Only the custom Activity created by inheriting the Activity itself needs to be registered in the project manifest file. The LoginActivity we created just now needs to be registered in the project manifest file by ourselves, and the RegisterActivity created based on the template has been registered for us by the system.
2. Register LoginActivity
You can set the properties of LoginActivity
Define the login variable in the string resource file strings.xml
Check the project list file again
Start the application and check the effect
What you see is the MainActivity window. If you want to see the LoginActivity window first when you want to start the application, you must set LoginActivity to start the Activity (Launcher Activity) in the project manifest file.
Fourth, set to start Activity
Set to start Activity by adding intent filter
1. Set LoginActivity to start Activity
Set up intent filter
Start the application and check the effect
2. Set RegisterActivity to start Activity
Set up intent filter
Start the application and check the effect
Questions: If the MainActivity is started, how can I jump to LoginActivity or RegisterActivity?