Android Learning notes (vi)

Source: Internet
Author: User

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)

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.