In the case of Android development, it is very easy for us to switch off the current activity, just one line of code this.finish;
So, what if you want to turn off other activity in the current activity?
For example, to change a setting, the program needs to rerun and load the new configuration file, you need to use restart or finish to restart the program.
You can refer to the following code:
It is recommended to use the first method, because finish off an activity and then start the activity in proportion to the whole program faster.
1. For a simple two activity, finish off the A interface in the B interface: first assign yourself to test_a in a
public class A_activity extends activity {public static a_activity test_a = null; @Overrideprotected void OnCreate (Bundle s Avedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); ... test_a = this;}}
Then call in B and finish off test_a.
public class B_activity extends activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {//TODO Auto-gener Ated method Stubsuper.oncreate (savedinstancestate); A_activity.test_a.finish (); }}
Other methods: Quit the program first, then run the program.
2. Re-run the program via Activitymanager
Activitymanager manager = (Activitymanager) getsystemservice (Activity_service); Manager.restartpackage (PackageName);
3. Either exit and rerun.
Exit the first Activity interface System.exit (0);//Reload Mainactivity interface for refresh effect intent Intent = new Intent (Settings.this, Mainactivity.class); startactivity (intent);
Finish off other activity in Android