One: Intent
Intent can be understood as intent.
We can define a jump intent by creating a intent instance, with intent to include: which page to jump to, what data to pass.
Then start the jump by startactivity (intent).
There are two ways of defining intent: Explicit intent, implicit intent.
Two: Explicit intent
1) We can define intent in the Java file of Actvity by code display, the parameter is: from which page, jump to which page.
New Intent (firstactivity. this, secondactivity. class ); startactivity (intent);
2) We can also pass the Putextra (Key,value) method, go to intent incoming data, carry to jump to the target page.
New Intent (firstactivity. this, secondactivity. class ); Intent.putextra (name, data); StartActivity (intent) ;
In the jump target page to the Java file, extract the intent instance that is linked to the Activyty through Getintent (), and then extract the data through the intent instance. Getxxextra (name), XX is the data type.
3) We can also get the Jump target page back to the data in the Jump initiation page
Jump Initiation Page:
Intent Intent =NewIntent (firstactivity. This, Secondactivity.class); Startactivityforresult (Intent,1);//The first parameter is intent, and the second is the request code//rewrite the result callback function, listen to the result code and the intent of the callback//first parameter: Request code: Used to verify the return result of a jump request initiated by the page//second parameter: Result code: Type of result code for callback//the third parameter: intent instance: The Jump target page carries the data through a intent, returning to the initiator page. @Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { Super. Onactivityresult (Requestcode, ResultCode, data); Switch(Requestcode) {//match the callback result of which jump request according to the request code Case1: if(ResultCode = = RESULT_OK) {//according to the result code, the operation of different result code is executed.String name = "Return_data"; String Returndata= Data.getstringextra (name);//extracting data from a postback intent......//working with data: Assigning values to variables, calling other functions, assigning values to view controls, etc. } Break; default: }}
Jump to target page:
New Intent (); // Create a intent instance of the callback Intent1.putextra (name, data); // Carry Data Setresult (RESULT_OK, intent1); // callback as a result
Android Learning Note Three: Using intent in tandem activity