Creation of activity
- First, a myactivity is automatically generated,
- Mainactivity inherits the class of Activity
- Override the onCreat method,
- Call the setContentView method again in the OnCreate method
- Set the layout to be displayed in the activity through setContentView
- This creates an activity
Use of activity
However, before using it, there is something similar to the ID card (i.e. a registered usage for him first)
1. In Android. xml has an activity tag 2. The name in the tag is the activity tag 3. If it is the activity of a main entry, set the label properties of action and category 4. In this way, the main entry of an application is successfully set
Layout and simple application of intent
> FActivity.java
//Register the click event, and realize the page Jump in the click event
btn.setOnClickListener( new OnClickListener() {
@Override
public void onClick(View v) {
/*The first parameter is a context object, which can be defined in two ways
* a.Because it operates on the current object, the context object is the current operation object. this.
* b.Or you can define a global variable first
* The second parameter represents the target file.
*
* So the intention of this sentence is to jump to the second page. But there is no activity to perform this intention.
* Now use start to perform the activity
*/
/* If it is for clicking events, an intention needs to be initialized!!!
*
* */
Intent intent = new Intent(FActivity.this,SActivity.class);
// Intention to start initialization
startActivity(intent);
}
});
SActivity.java
public class SActivity extends Activity{
@Override
protected void onCreate( Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sactivitty);
}
}
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".FActivity"
android:label="@string/app_name" >
<intent-filter> Priority start screen, the following part has not been modified
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.imoocdemo1.SActivity"
android:label="@string/app_name" >
</activity>
</application>