Android: Jump, Intent, with or without return value

Source: Internet
Author: User

2014-08-17

<!--first Page -    <TextViewAndroid:id= "@+id/textview1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignparentleft= "true"Android:layout_alignparenttop= "true"Android:layout_margintop= "126DP"Android:text= "parameter value returned" />    <ButtonAndroid:id= "@+id/button1"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignparenttop= "true"Android:layout_alignright= "@+id/textview1"Android:text= "No return value Jump" />    <ButtonAndroid:id= "@+id/button2"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:layout_alignright= "@+id/button1"Android:layout_below= "@+id/button1"Android:text= "return value Jump" />

<!---    <button        android:id= "@+id/ Button1 "        android:layout_width=" Match_parent "        android:layout_height  = "Wrap_content"        android:text= "button"/>

1 //first page of Java2 3  Public classMainactivityextendsactionbaractivity {4     PrivateButton bt1;5     PrivateButton bt2;6     PrivateTextView TV;7 8 @Override9     protected voidonCreate (Bundle savedinstancestate) {Ten         Super. OnCreate (savedinstancestate); One Setcontentview (r.layout.fragment_main); A  -         /** - * Two methods of jumping the * 1, no return value using startactivity (intent); - * 2, there are return results of the jump using Startactivityforresult (intent, requestcode); -          */ -BT1 =(Button) Findviewbyid (r.id.button1); +BT2 =(Button) Findviewbyid (r.id.button2); -TV =(TextView) Findviewbyid (r.id.textview1); +          ABt1.setonclicklistener (NewOnclicklistener () { at              - @Override -              Public voidOnClick (View v) { -                 //TODO Auto-generated method stubs -Intent Intent =NewIntent (mainactivity. This, change.class); -StartActivity (Intent);//The first of these methods in             } -         }); to          +Bt2.setonclicklistener (NewOnclicklistener () { -              the @Override *              Public voidOnClick (View v) { $                 //TODO Auto-generated method stubsPanax NotoginsengIntent Intent =NewIntent (mainactivity. This, change.class); -                 /** the * Second Method + * @intent: Intent Object A * @requestCode: The identity of the request, write here 1 the                  */ +Startactivityforresult (Intent, 1); -             } $         }); $     } -      -      the     /** - * Jump via Startactivityforresult, receive the returned dataWuyi * @requestCode: The identity of the request the * @resultCode: Receive the returned identity - * @data: Received data Wu      */ - @Override About     protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { $         //TODO Auto-generated method stubs -         Super. Onactivityresult (Requestcode, ResultCode, data); -         if(Requestcode==1 && resultcode==2) { -String content = Data.getstringextra ("Data"); A Tv.settext (content); +         } the     } -}

1 //second page of Java2 3  Public classChangeextendsactivity{4     PrivateButton bt;5     6 @Override7     protected voidonCreate (Bundle savedinstancestate) {8         //TODO Auto-generated method stubs9         Super. OnCreate (savedinstancestate);Ten Setcontentview (r.layout.change); One          ABT =(Button) Findviewbyid (r.id.button1); -Bt.setonclicklistener (NewOnclicklistener () { -              the @Override -              Public voidOnClick (View v) { -                 //TODO Auto-generated method stubs -Intent data =NewIntent (); +Data.putextra ("Data", "Hello"); -Setresult (2,data);//the identity sent out +Finish ();//Close Page A             } at         }); -          -     } -  -}

Display effect:

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.