Intent (i. Show using Intent)

Source: Internet
Author: User

Everyone knows that if the mobile phone has only one active application, then the application is too simple. Like a Web page, there are a number of components, in C # we can use the various skip control or code, here no longer repeat. So we're still creating an activity in the current project named Secondactivity and adding a btn button with the following code:

 Package Cn.hengzhe.tishi; Import android.support.v7.app.AppCompatActivity; Import Android.os.Bundle;  Public class extends   mainactivity {    @Override    protectedvoid  onCreate (Bundle Savedinstancestate) {        super. OnCreate (savedinstancestate);        Setcontentview (r.layout.second_layout);    }}
Activity
<?XML version= "1.0" encoding= "Utf-8"?><Relativelayoutxmlns: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/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context= "Cn.hengzhe.tishi.SecondActivity">    <ButtonAndroid:text= "Intent test"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparenttop= "true"Android:layout_alignparentleft= "true"Android:layout_alignparentstart= "true"Android:layout_marginleft= "72DP"Android:layout_marginstart= "72DP"Android:layout_margintop= "114DP"Android:id= "@+id/button" /></Relativelayout>
Layout file:

Once the above is created, we register at Manifests-androidmanifests.xml:

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Cn.hengzhe.tishi">    <ApplicationAndroid:allowbackup= "true"Android:icon= "@mipmap/ic_launcher"Android:label= "@string/app_name"Android:supportsrtl= "true"Android:theme= "@style/apptheme">        <ActivityAndroid:name=". Mainactivity ">            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>        <ActivityAndroid:name=". Secondactivity "></Activity>    </Application></Manifest>
Registration Activity

Because Secondactivity is not a master activity, you need to specify it with intent, overriding the button method in Mainiactivty:

Intent intent=New Intent (mainactivity.  this, secondactivity. class )  ;  StartActivity (intent);

*startactivity(): Specifically for start-up activities, as in C # or Java threads.

See here, probably all understand the usage of intent, tomorrow we continue to learn the methods of implicitly invoking intent.

Intent (i. Show using Intent)

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.