For example, there are two pages, a, B.
A parameter is passed to page B, after B, the processing page of the parameter is obtained, and the result is then passed back to page a with the parameter.
1.a Home mainactivity code type, such as the following:
Private button button; Private EditText result; Private final static int requestcode = 1;
@Override protected void onCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Button = (button) This.findviewbyid (r.id.button1); result = (EditText) This.findviewbyid (r.id.result); Button.setonclicklistener (New View.onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method stub
Intent Intent = new Intent (mainactivity.this,otheractivity.class); Intent.putextra ("A", "true"); Startactivityforresult (Intent,requestcode);}}); }
<pre name= "code" class= "HTML" > @Override protected void onactivityresult (int requestcode,int Resultcode,intent data) { Super.onactivityresult (Requestcode, ResultCode, data); if (ResultCode = = 2) { if (Requestcode = = Requestcode) {
<span style= "font-family:arial, Helvetica, Sans-serif;" >string c= Intent.getstringextra ("C");</span> Result.settext (c);}}
Pass the argument A to page B,the Onactivityresult function handles the number of references that are passed to page B .
<span style= "font-family:arial, Helvetica, Sans-serif;" ></span>
<span style= "font-family:arial, Helvetica, Sans-serif;" After the >2.otheractivity.java function processes a parameter, the C parameter is passed back to the a page. In the B page of the OnCreate inside processing </span>
<span style= "font-family:arial, Helvetica, Sans-serif;" ></span><pre name= "code" class= "HTML" > <pre name= "code" class= "html" > @Overridepublic void OnClick (View arg0) {//TODO auto-generated method stub Intent Intent = Getintent (); String a = Intent.getstringextra ("a"); String C; if (a== "true") { c = "It is true"; } else{ C = "It is false"; } Intent newintent = new Intent () Newintent.putextra ("C", c); Setresult (2,intent); Finish ();});
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Android Intent pass parameter return result (vi)