android系统退出代码实现
android系统退出实现,代码如下:
package com.sms.util;
import java.util.LinkedList;
import java.util.List;
import android.app.Activity;
import android.app.Application;
//实现Activity退出
public class MyApplication extends Application{
private List<Activity> activityList = new LinkedList<Activity>();
private static MyApplication instance;
private MyApplication(){
}
//单例实现返回MyApplication实例
public static MyApplication getInstance(){
if(null == instance){
instance = new MyApplication();
}
return instance;
}
//Activity加入到List中
public void addActivity(Activity activity){
activityList.add(activity);
}
//遍历每个Activity退出
public void exit(){
for(Activity activity:activityList){
activity.finish();
}
System.exit(0);
}
}