Completely exiting the current application system in Android

Source: Internet
Author: User

First, the unified management activity of the class Activitymanager copied into the project.

Package Com.jsmtr.www.helper;import Java.util.linkedlist;import Java.util.list;import android.app.Activity;import Android.app.application;public class Activitymanager extends Application {@SuppressWarnings ("rawtypes") Private Lis    T list = new LinkedList ();    private static Activitymanager instance; Private Activitymanager () {} public synchronized static Activitymanager getinstance () {if (null = = Instanc        E) {instance = new Activitymanager ();    } return instance;    } @SuppressWarnings ("Unchecked") public void addactivity (activity activity) {List.add (activity); } public void exit () {try {for (int i = 0; i < list.size (); i++) {Activity Activ                ity = (Activity) list.get (i);            if (activity! = null) activity.finish ();        }} catch (Exception e) {e.printstacktrace ();        } finally {system.exit (0); }} Public void Onlowmemory () {super.onlowmemory ();    System.GC (); }}

Second, in each Acitivity OnCreate method inside Add the current acitivity to ancivitylist inside go.

Activitymanager.getinstance (). addactivity (this);

Third, when you want to exit the system, call the Exit method in Activitymanager directly.

Activitymanager.getinstance (). exit ();

Completely exiting the current application system 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.