[Android] 7, page jump and intent simple usage

Source: Internet
Author: User

Here is a layout resource, 2 activity. First of all we know that the instantiation button and the Add button in the Mainactivity.java are known, and it is important to note that the 22nd line intent Intent = new Intent (Mainactivity.this, Otheractivity.class); Used to create an intent, and set the activity to be opened, and then in line 24 Intent.putextra ("Main", "I am sending data ~ wahaha"); Send message, previous string is the name of the message , followed by the message content, and finally started another activity.

1  Public classMainactivityextendsActivityImplementsOnclicklistener {2     //Claim Button3     PrivateButton Btnopen, btnhideactivity, btnexitactivity;4 5 @Override6      Public voidonCreate (Bundle savedinstancestate) {7         Super. OnCreate (savedinstancestate);8 Setcontentview (r.layout.main);9         //Instance buttonTenBtnopen =(Button) Findviewbyid (r.id.btnopen); OneBtnhideactivity =(Button) Findviewbyid (r.id.btnhideactivity); ABtnexitactivity =(Button) Findviewbyid (r.id.btnexitactivity); -         //add monitoring to each button -Btnopen.setonclicklistener ( This); theBtnhideactivity.setonclicklistener ( This); -Btnexitactivity.setonclicklistener ( This); -     } -  +      Public voidOnClick (View v) { -         if(v = =Btnopen) { +             //Create an intent and set the activity to be opened AIntent Intent =NewIntent (mainactivity. This, Otheractivity.class); at             //Send Data -Intent.putextra ("Main", "I am sending data ~ Wahaha"); -             //Start another activity -              This. StartActivity (intent); -}Else if(v = =btnhideactivity) { -              This. Finish ();//Exit Activity in}Else if(v = =btnexitactivity) { -System.exit (0);//Exit Program to         } +     } -}

In another activity, line 8th to 11th: Use intent intent = this.getintent (), get the current activity intent, and then get the contents of the name according to the name: String str = Intent.getstringextra ("Main") so that we can deliver the message between activity and activity ~

1  Public classOtheractivityextendsActivity {2     PrivateTextView TV;3 @Override4      Public voidonCreate (Bundle savedinstancestate) {5         Super. OnCreate (savedinstancestate);6TV =NewTextView ( This); 7 Setcontentview (TV);8         //get the current activity intent9Intent Intent = This. Getintent ();Ten         //Get Data OneString str = Intent.getstringextra ("Main"); A         //set the acquired data to TextView text - Tv.settext (str); -     } the}

This article link: http://www.cnblogs.com/zjutlitao/p/4230228.html

More Highlights: http://www.cnblogs.com/zjutlitao/p/

[Android] 7, page jump and intent simple usage

Related Article

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.