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)