The first is to call Setresult (int, Intent) in OnPause () in the activity after startup to set the returned Intent, but onactivityresult in the returned activity (Int,int, Intent) The resulting Intent is a null value of NULL.
This is the boot code
Findviewbyid (R.id.button1). Setonclicklistener (New Onclicklistener () {@Override public void OnClick (View v) {//TODO Auto-generated method Stubintent Intent = new Intent (mainactivity.this, mainactivity2.class); Bundle Sendbundle = new Bundle (), sendbundle.putcharsequence ("str", "from Mainactivity.class"); Intent.putextra (" Sendbundle ", Sendbundle); Startactivityforresult (intent,0x1001); }}); LOG.I (TAG, "oncreated");
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {//TODO auto-generated method Stubsuper.ona Ctivityresult (Requestcode, ResultCode, data); if (data!=null) {String str = Data.getstringextra ("return"); LOG.I (tag,str+ "" +requestcode+ "" +resultcode); if (resultcode==0x1001) {TextView TextView = (TextView) Findviewbyid ( R.ID.TEXTVIEW1); Textview.settext (str);}} ELSE{LOG.I (TAG, "data is null");}}
Above is the result returned by the callback method override
The following is the wrong setresult (int, Intent) code
protected void OnPause () {Intent Intent = new Intent (); Intent.putextra ("Return", "Return Me"); Setresult (0x1001, intent);}
After the reason is found, modify the above code to OnCreate (Bundle), add a button and append the onclick (View)
Findviewbyid (R.id.button2). Setonclicklistener (New Onclicklistener () {public void OnClick (View v) {Intent Intent = new in Tent (); Intent.putextra ("Return", "Return Me"); Setresult (0x1001, intent); finish (); The key here is to pass the intent back to the activity that started it and close the current activity});
About Activity.startactivityforresult (Intent, int) using