For example, there are two pages, a, B. A page to pass parameters to the B page, b page will get the parameters processed, and then the results are returned to page a with parameters.
The code for the main mainactivity class of the 1.a page is as follows:
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);}}
The parameter A is passed to page B,the Onactivityresult function handles the parameter C passed over the B page .
<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 ();});
Android intent to send a parameter back result (vi)