Analysis of data postback between Android pages _android

Source: Internet
Author: User

This article illustrates the method of data postback between Android pages. Share to everyone for your reference, specific as follows:

Requirements: Page 1 jump to page 2, page 2 and return to page 1 at the same time return data

Page 1, add the following code:

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

Page 2 to 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 return to page 1;
This.setresult (ACTIVITY.RESULT_OK, intent);/return page 1
this.finish ();

Page 1 receives returned 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 ();
  }


For more information on Android-related content readers can view the site: "The Android thread and message mechanism usage Summary", "Android programming activity Operation Skills Summary", "Android debugging techniques and common problems solution summary", " Android Development Primer and Advanced tutorials, Android Multimedia how-to summary (audio, video, recording, etc), summary of Android Basic components usage, Android View view tips, Android layout layout tips and A summary of the usage of Android controls

I hope this article will help you with the Android program.

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.