The layout and simple application of activity& intent

Posted by 0p3n_p0rT on Wed, 01 Jan 2020 19:53:07 +0100

Creation of activity

  1. First, a myactivity is automatically generated,
  2. Mainactivity inherits the class of Activity
  3. Override the onCreat method,
  4. Call the setContentView method again in the OnCreate method
  5. Set the layout to be displayed in the activity through setContentView
  6. 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


    //Register the click event, and realize the page Jump in the click event
        btn.setOnClickListener( new OnClickListener() {

            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

public class SActivity extends Activity{
        protected void onCreate( Bundle savedInstanceState) {
            // TODO Auto-generated method stub


        android:theme="@style/AppTheme" >

            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" />
            android:label="@string/app_name" >

Topics: Android xml Java