Android Classic Perfect Exit method

Source: Internet
Author: User

Android Classic Perfect Exit method, using singleton mode to create an activity management object, which has an activity container (specifically to implement its own processing, using LinkedList, etc.) is dedicated to storing the newly opened each activity, and easy to understand, Easy to operate, very good!

Apputils Class (stores each activity and implements the action to close all activity)

/** To change this template, choose Tools |  Templates * and open the template in the editor. */   Packagecom.cpic.jscx.android.utils; Importandroid.app.Activity; Importandroid.app.Application; Importjava.util.LinkedList; Importjava.util.List; /**  *  * @authoruser how to ask hovertree.com*/   Public classApputilsextendsapplication{PrivateList<activity> activitylist =NewLinkedlist<activity>(); Private StaticApputils instance; Privateapputils () {}//get a unique instance of an app in singleton mode              Public Staticapputils getinstance () {if(NULL==instance) {Instance=Newapputils (); }                   returninstance; }               //add activity to container why ask Hovertree.com              Public voidaddactivity (activity activity) {Activitylist.add (activity); }               //traverse all activity and finish              Public voidexit () { for(Activity activity:activitylist) {activity.finish (); } system.exit (0); }  }  

Add the activity to the Apputils object instance container in each activity's OnCreate method
Apputils.getinstance (). addactivity (this);

 Public void onCreate (Bundle savedinstancestate)  {      super. OnCreate (savedinstancestate);      Apputils.getinstance (). addactivity (this);      Setcontentview (r.layout.main);      Findviews ();  }   /* */

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

Android Classic Perfect Exit method

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.