Android returns a activity after opening B activity from a activity, and a activity state change will be used to refresh
Let me introduce the most common methods of my development.
Reference function Setresult and onactivityresult processing mechanism
To implement the principle of returning data in the return event of the second activity, the first activity reconstructs the Onactivityresult method, and in the event of refactoring the method, feels the data returned, making different processing. To achieve the effect of automatically updating the first Activity . For more information, refer to the following description. currently two activity,mainacivity and secondactivity;
1 //important code for a mainacivity:2 Public voidOnClick (View v) {3Intent Intent =NewIntent ();4Intent.setclass (mainactivity. This, Secondactivity.class);5Bundle bundle =NewBundle ();6LOG.V ("ANDROID.ABC", "!!!!!" +mainactivity. This. toString ());7Bundle.putstring ("UID", mainactivity. This. toString ());8 Intent.putextras (bundle);9 Startactivityforresult (intent,get_code);Ten } One A //b.secondactivity, in Onclicklistener -Findviewbyid (R.id.button). Setonclicklistener (NewView.onclicklistener () - { the @Override - Public voidOnClick (View v) - { -Setresult (RESULT_OK, (NewIntent ()). Setaction (UID)); + finish (); - } + }); A at //B. In mainactivity, rewrite the Onactivityresult method; - @Override - protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) - { - if(Requestcode = =Get_code) - { in if(ResultCode = =result_canceled) - { toText2.settext ("clicked Back"); + } - Else the { * if(Data! =NULL) $ { Panax NotoginsengText2.settext ("Results returned by the second activity: \ n" +data.getaction ()); - } the } + } A}
where static final private int get_code = 0; Is my custom constant to distinguish which activity is currently returned, and the following is the code for class Secondactivity:
Public classSecondactivityextendsactivity{string uid; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.second); Bundle Bundle= This. Getintent (). Getextras (); if(Bundle! =NULL) {UID= bundle.getstring ("UID"); } Findviewbyid (R.id.button). Setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {Setresult (RESULT_OK, (NewIntent ()). Setaction (UID)); Finish (); } }); }}
Return refresh of pages in Android