1.编写一个class继承Application
public class AppClose extends Application {
private List<Activity> mainActivity = new ArrayList<Activity>();
public List<Activity> MainActivity() {
return mainActivity;
}
public void addActivity(Activity act) {
mainActivity.add(act);
}
public void finishAll() {
for (Activity act : mainActivity) {
if (!act.isFinishing()) {
act.finish();
}
}
mainActivity = null;
}
}
2.在Activity 中的oncreate方法中添加
AppClose appState = (AppClose)this.getApplication();
appState.addActivity(this);
// setContentView(R.layout.main);
3.//设定点击事件
button.setonclick....(){
AppClose appState = (AppClose)getApplicationContext();
appState.finishAll();
}
4.在注册清单文件中
给application添加属性 android:name=".AppClose"