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.