package com.shoujifeng.win.winutil;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
/**
* 完全退出程序辅助类
*
*
*
*/
public class ExitApplication {
// 存储已打开的Activity集合
private List<Activity> listActivity = new ArrayList<Activity>();
// 单例的ExitApplication,目的是在任何的Activity中用的都是同一个集合
private static ExitApplication exitApplication;
private ExitApplication() {
}
public static ExitApplication getInstance() {
if (null == exitApplication) {
exitApplication = new ExitApplication();
}
return exitApplication;
}
/**
* 添加Activity到集合中(在每个Acitivity的onCreate方法中调用)
*/
public void addActivity(Activity activity) {
listActivity.add(activity);
}
/**
* 完全退出程序(在准备退出系统的时候调用)
*/
public void exit(Context context) {
Dialog dialog = new AlertDialog.Builder(context).setTitle("确认退出")
.setMessage("确定退出设计联?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
for (Activity activity : listActivity) {
activity.finish();
}
System.exit(0);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}).create();
dialog.show();
}
}
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
/**
* 完全退出程序辅助类
*
*
*
*/
public class ExitApplication {
// 存储已打开的Activity集合
private List<Activity> listActivity = new ArrayList<Activity>();
// 单例的ExitApplication,目的是在任何的Activity中用的都是同一个集合
private static ExitApplication exitApplication;
private ExitApplication() {
}
public static ExitApplication getInstance() {
if (null == exitApplication) {
exitApplication = new ExitApplication();
}
return exitApplication;
}
/**
* 添加Activity到集合中(在每个Acitivity的onCreate方法中调用)
*/
public void addActivity(Activity activity) {
listActivity.add(activity);
}
/**
* 完全退出程序(在准备退出系统的时候调用)
*/
public void exit(Context context) {
Dialog dialog = new AlertDialog.Builder(context).setTitle("确认退出")
.setMessage("确定退出设计联?")
.setPositiveButton("确定", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
for (Activity activity : listActivity) {
activity.finish();
}
System.exit(0);
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}).create();
dialog.show();
}
}