Finish off other activity in Android

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.