标签:保存 click override etc cti set 运行程序 oid 集合类
public class ActivityCollector {
public static List<Activity> activities=new ArrayList<>();
public static void addActivity(Activity activity){
activities.add(activity); //用于向list中添加活动
}
public static void removeActivity(Activity activity) {
activities.remove(activity); //用于从list中移除活动
}
public static void finishAll() {
for(Activity activity:activities){
if(!activity.isFinishing()){
activity.finish(); //将list中存储的活动全部销毁掉
}
}
}
}
public class BaseActivity extends AppCompatActivity{
@Override
protected void onCreate(Bundle savedInstanceState){ //获取实例的类名
super.onCreate(savedInstanceState); //保存实例类名
Log.d("BaseActivity",getClass().getSimpleName()); //打印
ActivityCollector.addActivity(this); //调用ActivityCollerctor中的addActivity方法
}
//@Override
protected void onDestory(){
super.onDestroy();
ActivityCollector.removeActivity(this);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Button button=(Button) findViewById(R.id.button3);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ActivityCollector.finishAll();//销毁该项目的所有活动
}
});
}
标签:保存 click override etc cti set 运行程序 oid 集合类
原文地址:http://www.cnblogs.com/aqyl/p/6666515.html