Android notes (20) Jump and value transfer in activity

Source: Internet
Author: User

We know that an app is composed of a number of activity, then the individual acitivity will need to jump and pass the value to ensure the operation of the app, now summarizes the multiple activity between the jump and value transfer.

A simple jump

Androidmanifest.xml

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Cn.lixyz.activitymanager">    <ApplicationAndroid:allowbackup= "true"Android:icon= "@mipmap/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=". Secondactivity ">        </Activity>    </Application></Manifest>
View Code

Mainactivity.java

 PackageCn.lixyz.activitymanager;Importandroid.content.Intent;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.util.Log;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View; Public classMainactivityextendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Findviewbyid (R.id.bt_submit). Setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {Intent Intent=NewIntent (mainactivity. This, Secondactivity.class);            StartActivity (Intent);    }        }); }}
View Code

Activity_main.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"Tools:context=". Mainactivity "android:orientation= "vertical">    <EditTextAndroid:id= "@+id/ed_input"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter the value you want to pass"/>    <ButtonAndroid:id= "@+id/bt_submit"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Submit"        /></LinearLayout>
View Code

Secondactivity.java

 PackageCn.lixyz.activitymanager;Importandroid.app.Activity;ImportAndroid.os.Bundle;/*** Created by LGB on 2015/8/27.*/ Public classSecondactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);    Setcontentview (R.layout.activity_second); }}
View Code

Activity_second.xml

<?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">    <TextViewAndroid:id= "@+id/tv_text_show"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Default Text"Android:textcolor= "#00ff00"android:textsize= "90SP" /></LinearLayout>
View Code

as can be seen from the code, we use StartActivity () in an activity to pass in a intent object to jump between activity.

Operation Result:

Android notes (20) Jump and value transfer in activity

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.