Activity is an application component that provides users with a visual interface for convenient operations, such as calling, taking photos, sending emails or browsing maps. Each activity provides a visual window, which overwrites the entire screen, however, in some cases, some smaller windows may float on another window.
Next, we will add a new Activity for the Android app.
Step 1: Create a class that inherits the Activity, such as MainActivity.
Package com. ljq. activity;
Import android. app. Activity;
Import android. OS. Bundle;
Public class MainActivity extends Activity {
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// Use setContentView to display a view
SetContentView (R. layout. main );
}
}
Step 2: add the above Activity configuration code to the AndroidManifest. xml file in the function list.
<? Xml version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. ljq. activity"
Android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">
<Application android: icon = "@ drawable/icon" android: label = "@ string/app_name">
<! --. Indicates that MainActivity is the class under com. ljq. activity of the current package. If the class is in the current application package, the dot symbol can be omitted. If the class must be added under the application package,
For example, the MainActivity class can be written in the com. ljq. activity. user package as follows: <activity android: name = ". user. MainActivity"/> -->
<Activity android: name = ". MainActivity" android: label = "@ string/app_name">
<! --
1. An application can have multiple activities, each of which is at the same level. Which Activity is the first to start when the program is started?
Some programs may need to be displayed in the program list, while others do not. How to define it?
Android. intent. action. MAIN determines the Activity that the application starts first.
Android. intent. category. LAUNCHER determines whether the application is displayed in the program list.
2. Because your program may have many activities, as long as the xml configuration file contains such an intent-filter, and this launcher exists in it, this activity is the first activity to run when you click a program.
3. Now there is only one activity, so adding or not adding does not matter. The activity that is enabled by default when the simulator is started.
-->
<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>
</Activity>
</Application>
<Uses-sdk android: minSdkVersion = "7"/>
</Manifest>