I. Returning data from activity
1. OnCreate when the button is clicked
Startactivityforresult (Intent, 0);
2. Onactivityresult method of receiving data completion
@Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {//TODO auto-generated met Hod stub if (data==null) return; Bundle Bundle=data.getextras (); String phonenumer= (String) bundle.getstring ("Phonenumer") Edt.settext (Phonenumer); }
3. Passing values
Intent intent=new Intent () Intent.putextra ("PhoneNumber", Phonenumber.gettext (). toString ()); Setresult (0,intent); Finish ();
Second, the request code and the result code
The new activity is not in the same thread as the main activity, and when the new activity is closed, the main activity is triggered
Onactivityresult event.
Startactivityforresult (Intent Intent, int requestcode): The main activity jumps with the request code a new activity interface.
Onactivityresult (int requestcode, int resultcode, Intent data)
-Requestcode: This parameter can be used to determine which interface is coming back from.
-ResultCode, data: Sent back by the closed interface
when we close the new activity, it triggers the Onactivityresult method of the main acvitity, then because before the main activity sent a request code, this time can be based on the request code to determine from which interface back.
* setresult (int resultcode): Sets the data passed to the previous interface
* setresult (int resultcode, Intent data): Set up a pass to the previous interface
You can also set some result code information when you return to the main activity from the new activity.
Android Learning notes (vi)