Explicit activation and implicit activation activity for Android learning

Source: Internet
Author: User

There are two layout files in the Res interface Activity_main and Acivity_two

Activity_main has the following four buttons

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Tools:context= "Com.example.twoactivity.MainActivity" >    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "I am the first interface" />    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:onclick= "click"Android:text= "Jump to Second interface" />    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:onclick= "Click2"Android:text= "One app for activating the system" />    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:onclick= "Click3"Android:text= "Implicit intent to jump to the second interface" />         <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:onclick= "Click4"Android:text= "interface to activate SMS" /></LinearLayout>

Acivity_two.xml

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical"Tools:context= "Com.example.twoactivity.MainActivity" >    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "I am the second interface" />    <ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"android:src= "@drawable/abc_menu_dropdown_panel_holo_dark" />    <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:onclick= "click"Android:text= "Jump to Second interface" /></LinearLayout>

Now we need to click "Jump to Second page" in Main, let the program show to jump to two pages inside

Below we create two classes under SRC, inheriting the activity class

Mainactivity.java

 Packagecom.example.twoactivity;ImportAndroid.annotation.SuppressLint;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;Importandroid.support.v7.app.ActionBarActivity;ImportAndroid.view.View; Public classMainactivityextendsactionbaractivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_main); }    //jump to the second screen when the user clicks the button     Public voidClick (View view) {//Click the button to activate the second interface, jump//Intent Intent        /** Intent Intent = new Intent (); Intent.setclassname (This, * "Com.example.twoactivity.OtherScreenActiv         ity ");//Set this intent to activate the component * startactivity (intent); */Intent Intent=NewIntent ( This, Otherscreenactivity.class);    StartActivity (Intent); }     Public voidClick2 (view view) {//Click the button to activate the second interface, jump//Intent IntentIntent Intent=NewIntent (); Intent.setclassname ("Com.android.gallery",                "Com.android.camera.GalleryPicker");//set the component to be activated by this intentstartactivity (Intent); }    /*** Use implicit intent to activate the third interface * **/@SuppressLint ("Newapi")     Public voidClick3 (view view) {//Click the button to activate the second interface, jump//Intent IntentIntent Intent=NewIntent (); Intent.setaction ("Com.example.xxx"); Intent.addcategory ("Android.intent.category.DEFAULT"); //Specifying data Types//If only the type has no data//Intent.settype ("Vnd.android.cursor.item/haha"); //If only the data has no type//Intent.setdata (Uri.parse ("Itheima:gagaga")); //if there are types and data that haveIntent.setdataandtypeandnormalize (Uri.parse ("Itheima:gagaga"),                "Vnd.android.cursor.item/haha");        StartActivity (Intent); //Action Data//assault, soy sauce.//tea, girls.//Bubble green tea, bubble red, bubble black dragon//addcategory Additional Information    }    /*** Activation of SMS Service * **/     Public voidClick4 (view view) {Intent Intent=NewIntent (); Intent.setaction ("Adnroid.intent.action.SENDTO"); Intent.addcategory ("Android.intent.category.DEFAULT"); Intent.setdata (Uri.parse ("Sms:110"));    StartActivity (Intent); }}

Otherscreenactivity.java

 Packagecom.example.twoactivity;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.widget.Toast;/*** activity is one of the important components of the system. To find activity, you must configure it in the manifest file * **/ Public classOtherscreenactivityextendsActivity {//OnCreate method for overriding activity@Overrideprotected voidonCreate (Bundle savedinstancestate) {//TODO auto-generated Method Stub        Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_two); Intent Intent= Getintent ();//get to activate his intentionsUri uri =Intent.getdata (); String result=uri.tostring (); Toast.maketext ( This, "Data is:" + result, 0). Show (); }}

And in the light file inside Androidmanifest.xml

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.ce"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "8"android:targetsdkversion= "+" />    <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >        <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>        <ActivityAndroid:name=". Resultactivity "Android:label= "@string/app_name" >        </Activity>    </Application></Manifest>

Explicit activation and implicit activation activity for Android learning

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.