A day suddenly thought of the title problem, generally return to the previous activity, the current activity should be automatically destroyed. If you want to keep the value, you think of the way in which bundles are passed
Finally the function is realized, but the feeling method is very stupid.
The main code is as follows:
1 PackageCom.example.valuepass;2 3 ImportCOM.EXAMPLE.PROGRAMDEMO.R;4 5 Importandroid.app.Activity;6 Importandroid.content.Intent;7 ImportAndroid.os.Bundle;8 ImportAndroid.util.Log;9 ImportAndroid.view.View;Ten ImportAndroid.view.View.OnClickListener; One ImportAndroid.widget.Button; A ImportAndroid.widget.EditText; - - the Public classMainactivityextendsActivity { - PrivateEditText Et_phonenumber; - PrivateButton Bt_next; - Private intACTIVITY1 = 1; + Private intUSERNAME = 2; - PrivateBundle bundle =NewBundle (); + PrivateIntent Intent =NewIntent (); A PrivateString TAG = "Mainactivity"; at PrivateString username; - @Override - protected voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); -Et_phonenumber =(EditText) Findviewbyid (r.id.et_phonenumber); inBt_next =(Button) Findviewbyid (r.id.bt_next); - toBt_next.setonclicklistener (NewOnclicklistener () { + @Override - Public voidOnClick (View v) { theBundle.putstring ("PhoneNumber", Et_phonenumber.gettext (). toString ()); * log.v (Tag,et_phonenumber.gettext (). toString ()); $Bundle.putstring ("username", username);Panax Notoginseng Intent.putextras (bundle); -Intent.setclass (mainactivity. This, Username.class); the Startactivityforresult (intent,activity1); + } A }); the } + - @Override $ protected voidOnactivityresult (intRequestcode,intresultcode,intent data) { $ if(Requestcode = =ACTIVITY1) { - if(ResultCode = =USERNAME) { - Bundle Getbundle; theGetbundle =Data.getextras (); -Username = getbundle.getstring ("username");Wuyi log.v (tag,username); the } - } Wu Super. Onactivityresult (Requestcode, ResultCode, data); - } About $}
1 PackageCom.example.valuepass;2 3 ImportCOM.EXAMPLE.PROGRAMDEMO.R;4 5 Importandroid.app.Activity;6 Importandroid.content.Intent;7 ImportAndroid.os.Bundle;8 ImportAndroid.util.Log;9 ImportAndroid.view.View;Ten ImportAndroid.view.View.OnClickListener; One ImportAndroid.widget.Button; A ImportAndroid.widget.EditText; - ImportAndroid.widget.TextView; - the Public classUsernameextendsactivity{ - PrivateTextView Et_phonenumber; - PrivateEditText Et_username; - PrivateButton Bt_next; + PrivateButton Bt_back; - PrivateBundle bundle =NewBundle (); + PrivateIntent Intent =NewIntent (); A Private intUSERNAME = 2; at PrivateString TAG = "Username"; - - @Override - Public voidonCreate (Bundle savedinstancestate) { - Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.username); inEt_phonenumber =(TextView) Findviewbyid (r.id.et_phonenumber); -Et_username =(EditText) Findviewbyid (r.id.et_username); toBt_next =(Button) Findviewbyid (r.id.bt_next); +Bt_back =(Button) Findviewbyid (r.id.bt_back); -bundle = This. Getintent (). Getextras (); theLOG.V (tag,bundle.getstring ("PhoneNumber")); *Et_phonenumber.settext (bundle.getstring ("PhoneNumber")); $Et_username.settext (bundle.getstring ("username"));Panax Notoginseng -Bt_next.setonclicklistener (NewOnclicklistener () { the @Override + Public voidOnClick (View v) { ABundle.putstring ("username", Et_username.gettext (). toString ()); the Intent.putextras (bundle); +Intent.setclass (Username. This, Finish.class); - startactivity (intent); $ } $ }); - -Bt_back.setonclicklistener (NewOnclicklistener () { the @Override - Public voidOnClick (View v) {WuyiBundle Bundle_back =NewBundle (); theBundle_back.putstring ("username", Et_username.gettext (). toString ()); -LOG.V (tag,bundle_back.getstring ("username")); Wu Intent.putextras (bundle_back); - Setresult (username,intent); About onbackpressed (); $ } - }); - } - A}
Username.java
1 PackageCom.example.valuepass;2 3 ImportCOM.EXAMPLE.PROGRAMDEMO.R;4 5 Importandroid.app.Activity;6 ImportAndroid.os.Bundle;7 ImportAndroid.widget.TextView;8 9 Public classFinishextendsactivity{Ten PrivateTextView Et_phonenumber; One PrivateTextView Et_username; A PrivateBundle bundle =NewBundle (); - @Override - Public voidonCreate (Bundle savedinstancestate) { the Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.finish); - -bundle = This. Getintent (). Getextras (); +Et_phonenumber =(TextView) Findviewbyid (r.id.et_phonenumber); -Et_username =(TextView) Findviewbyid (r.id.et_username); +Et_phonenumber.settext (bundle.getstring ("PhoneNumber")); AEt_username.settext (bundle.getstring ("username")); at } - -}
Finish.java
PS: Later on the internet to see similar problems, someone answered:
Add flag to activate activity
Intent.flag_activity_reorder_to_front This sign says: If the activity has started, it will not generate new activity, but just add the activity instance to the top of the stack.
I'm going to have time to try. But it seems to change onbackpressed ();
Code download
Android Step-up registration, activity from B to return a modify and then go to the b,b filled in the same