Transfer simple data when activity jumps

Source: Internet
Author: User

I. Create a new Empty project

Two. Add a button to the main interface

Three. Create a new empty activity and name it Theaty

Four. Modifying the OnCreate function in Mainactivity.java

 protected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Findviewbyid (R.id.btnstartaty). Setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {Intent I=NewIntent (mainactivity. This, Theaty.class); I.putextra ("Data", "Hello Android");//Pass a string argument with the name value "Data" and the value "Hello AndroidStartActivity (i);//Start another activity            }        }); }

Five. Add the ID number to the TextView in the Theaty layout file

<android:text= "@string/hello_world"  android:layout_width= "Wrap_ Content "        android:layout_height=" Wrap_content "        android:id=" @+id/ TV "/>

Six. Modify the OnCreate function in the Theaty source code file

Private TextView TV; // First, add a TextView member variable protected void onCreate (Bundle savedinstancestate) {        super. OnCreate (savedinstancestate);        Setcontentview (r.layout.activity_the_aty);         = Getintent (); // get the relevant intent        TV = (TextView) Findviewbyid (r.id.tv);        Tv.settext (I.getstringextra ("Data")); // set the value in the text box    }

Seven. Running

Transfer simple data when activity jumps

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.