android退出所有的activity
Android經(jīng)典完美退出方法,使用單例模式創(chuàng)建一個(gè)Activity管理對(duì)象,該對(duì)象中有一個(gè)Activity容器(具體實(shí)現(xiàn)自己處理,使用LinkedList等)專門負(fù)責(zé)存儲(chǔ)新開啟的每一個(gè)Activity,并且容易理解、易于操作,非常不錯(cuò)!
本文引用地址:http://m.butianyuan.cn/article/201610/305646.htmAppUtils類(儲(chǔ)存每一個(gè)Activity,并實(shí)現(xiàn)關(guān)閉所有Activity的操作)
/*
* 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.LinkedList;
import java.util.List;
/**
*
* @author user
*/
public class AppUtils extends Application{
private List activityList = new LinkedList();
private static AppUtils instance;
private AppUtils()
{
}
//單例模式中獲取唯一的app實(shí)例
public static AppUtils getInstance()
{
if(null == instance)
{
instance = new AppUtils();
}
return instance;
}
//添加Activity到容器中
public void addActivity(Activity activity)
{
activityList.add(activity);
}
//遍歷所有Activity并finish
public void exit()
{
for(Activity activity:activityList)
{
activity.finish();
}
System.exit(0);
}
}
評(píng)論