1, if the button in the Mainactivity.java click on the settings:
Send data method Simple Type
I.putextra ("txt", "Yes, I just came from the message!");
Send data Method 2--Complex Type
Bundle data = new bundle ();
Data.putstring ("txt", "amount, I am a complex type of data method sent to!") ");
I.putextras (data);
When the return value is included, start with the Startactivityforresult (intent, Requestcode) method, without startactivity (intent), i.e.: Startactivityforresult (i, 0) ;
2. At the same time, set the receive processing return value method:
@Override
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
The return value will be processed here
Super.onactivityresult (Requestcode, ResultCode, data);
}
3. Set the result data on the return value page Page1.java
Intent i = new Intent ();
I.putextra ("Rerult", "I am the return value Wow! ");
Setresult (0, I);
4. The return value is processed in the Receive return value page;
@Override
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
Determines whether a value is non-null
if (data! = NULL) {
String result = Data.getstringextra ("Rerult");
Textview1.settext (result);
}
Super.onactivityresult (Requestcode, ResultCode, data);
}
Tips:textview1 is the text field within the associated layout file that receives the return value page.
5, OK, details can download the following source code: source Download
How to send and receive data (two methods) in Android?