Intent (1. intent is used for display). intent is used for display.
Everyone knows that if a mobile phone has only one activity application, it would be too simple. Like a Web page, there are multiple components. In C #, we can use various program skip controls or codes. I will not go into details here. In this case, create a SecondActivity in the current project and add a BTN button. The Code is as follows:
package cn.hengzhe.tishi;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;public class SecondActivity extends MainActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_layout); }}
Activity
<? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: id = "@ + id/second_layout" android: layout_width = "match_parent" android: layout_height = "match_parent" android: paddingBottom = "@ dimen/activity_vertical_margin" android: paddingLeft = "@ dimen/plugin" android: paddingRight = "@ dimen/plugin" android: paddingTop = "@ dimen/activity_vertical_margin" tools: context = "cn. hengzhe. tishi. secondActivity "> <Button android: text =" Intent test "android: layout_width =" wrap_content "android: layout_height =" wrap_content "android: layout_alignParentTop =" true "android: expiration = "true" android: layout_alignParentStart = "true" android: layout_marginLeft = "72dp" android: layout_marginStart = "72dp" android: layout_marginTop = "114dp" android: id = "@ + id/button"/> </RelativeLayout>
Layout file:
After the above is created, we register in the manifests-AndroidManifests.xml:
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.hengzhe.tishi"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SecondActivity"></activity> </application></manifest>
Registration activities
Because SecondActivity is not a main activity, you need to use intent to specify it. Rewrite the button method in MainiActivty:
Intent intent=new Intent(MainActivity.this, SecondActivity.class) ; startActivity(intent);
* StartActivity (): Used to start an activity, which is the same as that of a C # or JAVA thread.
Now, I understand the usage of Intent. Tomorrow we will continue to learn the methods for implicitly calling intent.