Android 解决应用退出 Activity 无法完全退出的问题

public class ExitApplication extends Application{

private List<Activity> activitys = new LinkedList<Activity>();
private static ExitApplication instence;
private  UserData loginUser ;
private  ExitApplication(){
}
//获得ExitApplication实例 
public static ExitApplication getInstence() {
if(null == instence){
instence = new ExitApplication();
}
return instence;
}
//添加activity到list
public void addActivity(Activity activity){
if(!activitys.contains(activity)){
activitys.add(activity);
}

}
//退出时杀掉所有Activity
public  void exit(){
if(!activitys.isEmpty()){
for(Activity activity :activitys){
activity.finish();
}
}
System.exit(0);
}
public UserData getLoginUser() {
return loginUser;
}
public void setLoginUser(UserData loginUser) {
this.loginUser = loginUser;
}

}

你可能感兴趣的:(Activity)