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