End all activities and services by completely exiting the application.

Source: Internet
Author: User
 below is the end of the entire application used in my project. exiting all activities includes services: 
Import Java. util. using list; import Java. util. list; import android. app. activity; import android. app. application; public class myapplication extends application {private list <activity> activitylist = new extenlist <activity> (); Private Static myapplication instance; private myapplication () {}// obtain the unique myapplication instance public static myapplication getinstance () {If (null = instance) {instance = new myapplication ();} return instance;} in singleton Mode ;} // Add the activity to the container public void addactivity (activity) {activitylist. add (activity) ;}// traverse all activities and finishpublic void exit () {New mycommondialog ("saving data .. ") {@ overrideprotected string donouiopt () {// todo auto-generated method stubfor (activity: activitylist) {activity. finish ();} return Super. donouiopt () ;}@ overrideprotected void Doback (string success) {// todo auto-generated method stubsystem. exit (0); super. doback (SUCCESS );}};}}

In the exit () method, you can directly use: for (activity: activitylist) {activity. Finish ();} return Super. donouiopt (); system. Exit (0 );

 
Mycommondialog is a custom prompt class, which can be removed directly.

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.