Exit all apps, monitor what activity is open

Source: Internet
Author: User

1. New class activity manager class Activitycollector
 Public classActivitycollector { Public StaticList<activity>activities =NewArraylist<activity>();  Public Static voidaddactivity (activity activity) {Activities.add (activity); }     Public Static voidremoveactivity (activity activity) {activities.remove (activity); }     Public Static voidFinishall () { for(Activity activity:activities) {if(!activity.isfinishing ())            {activity.finish (); }        }    }}

Provides a addactivity () method for Adding an activity to the list

Provides a removeactivity () method to remove an activity from the list

Finally, a Finishall () method is provided to destroy all the activities stored in the list

2. New class baseactivity inherit from activity

The

does not set the interface in Baseactivity, . They will also inherit everything from the activity;

 public  class  baseactivity extends   Activity {@Override  protected  void   OnCreate (Bundle Savedinstancestate) { super  .oncreate (        Savedinstancestate); LOG.D ( "baseactivity", GetClass (). Getsimplename ()); //         monitor which activity starts     Activitycollector.addactivity (this   protected  void   OnDestroy () { //activity off, remove the activity from activities  
Super . OnDestroy (); Activitycollector.removeactivity (this); } }
3. When you need to, callActivitycollector.finishall (); You can turn off all activities!

Exit all apps, monitor what activity is open

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.