Android Learning Note Three: Using intent in tandem activity

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.