Android classic exit method, android classic exit

Source: Internet
Author: User

Android classic exit method, android classic exit

Android classic perfect exit method: creates an Activity management object in singleton mode. This object has an Activity container (which can be processed by yourself and used in sort list) it stores every newly opened Activity, which is easy to understand and operate!

AppUtils class (stores every Activity and closes all activities)

/** To change this template, choose Tools | Templates * and open the template in the editor. */package com. cpic. jscx. android. utils; import android. app. activity; import android. app. application; import java. util. using list; import java. util. list;/***** @ author user he asked hovertree.com */public class AppUtils extends Application {private List <Activity> activityList = new extenlist <Activity> (); private static AppUtils instance; private AppUtils () {}// obtain the unique public static AppUtils getInstance () {if (null = instance) of the app instance in singleton Mode) {instance = new AppUtils ();} return instance;} // Add the Activity to the container and ask hovertree.com public void addActivity (Activity activity) {activityList. add (activity);} // traverse all activities and finish public void exit () {for (Activity: activityList) {activity. finish ();} System. exit (0 );}}

Add the Activity to the AppUtils object instance container in the onCreate method of each Activity
AppUtils. getInstance (). addActivity (this );

Public void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); AppUtils. getInstance (). addActivity (this); setContentView (R. layout. main); findViews ();}/* He asked hovertree.com */

Recommended: http://www.cnblogs.com/roucheng/p/androidjiqiao.html

Related Article

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.