Data backhaul between Android pages

Source: Internet
Author: User

Data backhaul between Android pages

Requirements: Page 1 jump to page 2, page 2 and return to page 1 also return data

Page 1 adds the following code:

Intent Intent = new Intent ();   Intent.setclass (page 1.this, page 2.class);   Bundle bundle = new bundle ();   Intent.putextras (bundle);//Add bundles to intent, or you can add data from bundles to the next page, for example: Bundle.putstring ("abc", "BBB");   Startactivityforresult (Intent, 0);//jump and ask for the return value, 0 for the request value (can be written casually)

Page 2 receive data add code as follows:

Intent Intent = This.getintent (); Bundle bundle = Intent.getextras (), bundle.putstring ("AAA", "Back"),//Add the Data Intent.putextras (bundle) to be returned to page 1; This.setresult (ACTIVITY.RESULT_OK, intent);//Return to page 1this.finish ();

Page 1 receive return Data: (need to rewrite Onactivityresult)

@Override    protected void onactivityresult (int requestcode, int resultcode, Intent data) {        Super.onactivityresult (Requestcode, ResultCode, data);        if (Requestcode = = 0 && ResultCode = = ACTIVITY.RESULT_OK) {            Bundle bundle = Data.getextras ();            gameview.backstring = bundle.getstring ("AAA");             Toast.maketext (This, backstring, Toast.length_short). Show ();        }    }

Data backhaul between Android pages

Related Article

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.