Android display intent to activate another actitity

Source: Internet
Author: User

1. Jump to a new actitity

New project, create a new Java class otherscreenactivity inherit from activity class

 Packagecom.wuyudong.twoactivity;Importandroid.app.Activity;ImportAndroid.os.Bundle;//activity is an important component of the system//the OS must be configured in the manifest file to find the activity Public classOtherscreenactivityextendsActivity {//override Activity's OnCreate method method to set the interface of the initialization program@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_two); }}

Obviously need to create a new android.xml named Activity_two, write some control layout

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" >    <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "button" />    <ProgressBarAndroid:id= "@+id/progressbar1"style= "? Android:attr/progressbarstylelarge"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content" /></LinearLayout>

The code in Mainactivity.java is as follows

 Packagecom.wuyudong.twoactivity;ImportAndroid.os.Bundle;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.view.View; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_main); }        //jump to the second page when the user clicks on a button     Public voidClick (View view) { Intent Intent = new  Intent (); Intent.setclassname (This, "com.wuyudong.twoactivity.OtherScreenActivity");    StartActivity (intent); }}

Of course, the code in Click can also be changed to the following form:

    // jump to the second page    when the user clicks on a button  Public void Click (View view) {        //Intent Intent = new Intent ();         // Intent.setclassname (This, "com.wuyudong.twoactivity.OtherScreenActivity");        New Intent (This, otherscreenactivity.  Class);        StartActivity (intent);    }

The manifest file Androidmanifest.xml is as follows:

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.wuyudong.twoactivity"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:icon= "@drawable/icon1"Android:name= "Com.wuyudong.twoactivity.MainActivity"Android:label= "@string/activity01" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>         <ActivityAndroid:icon= "@drawable/icon2"Android:name= "Com.wuyudong.twoactivity.OtherScreenActivity"Android:label= "@string/activity02" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>    </Application></Manifest>

Where drawable is the new folder under the Res folder, Icon1 and Icon2 are the pictures that are put in

The Activity_main.xml code is as follows:

<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=". 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" /></LinearLayout>

The final interface is as follows:

Click the button to jump to the second page

2. The interface of the application that activates the system

For Intent.setclassname (string packagename, string className);

When we do not know the application of PackageName and classname, click on the app icon to view logcat log information , the following is the information I displayed after clicking on the gallery icon:

07-11 09:31:44.153:i/activitymanager (1227): START u0 {act=android.intent.action.main cat=[ Android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.android.gallery/com.android.camera.gallerypicker } from PID 1512

Add the corresponding button event code as follows:

        // The app    that activates the gallery when the user taps the button // Com.android.gallery/com.android.camera.gallerypicker     Public void Click2 (view view) {         new  Intent ();         Intent.setclassname ("Com.android.gallery", "Com.android.camera.GalleryPicker");         StartActivity (intent);     }

This implements the interface of the application that activates the system

Here's a look at the scenario: jump to the system's Web interface when the connection fails

The code is as follows:

 Packagecom.wuyudong.testnetwork;ImportAndroid.net.ConnectivityManager;ImportAndroid.net.NetworkInfo;ImportAndroid.os.Bundle;ImportAndroid.widget.Toast;Importandroid.app.Activity;ImportAndroid.content.Context;Importandroid.content.Intent; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); //Check the user's network situationConnectivitymanager cm = (Connectivitymanager) This. Getsystemservice (Context.connectivity_service); Networkinfo Info=Cm.getactivenetworkinfo (); if(Info! =NULL&&info.isconnected ()) {Toast.maketext ( This, "Network available", 0). Show (); } Else{Toast.maketext ( This, "Network Unavailable", 0). Show (); //user-oriented interface to the system networkIntent Intent =NewIntent (); //07-11 15:11:47.488:i/activitymanager (859)://starting:intent {act=android.intent.action.main cmp=com.android.settings/. Wirelesssettings} from PID 1293Intent.setclassname ("Com.android.settings", "com.android.settings.WirelessSettings");        StartActivity (Intent); }    }}

Android Display activates another actitity

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.