Intent (1. intent is used for display). intent is used for display.

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.