获得当前活动名称
getClass.getSimpleName();
退出应用
public class ActivityCollector {
public static List<Activity>activities=new ArrayList<Activity>();
public static void addActivity(Activity activity){
activities.add(activity);
}
public static void removeActivity(Activity activity){
activities.remove(activity);
}
//测试finishAll()方法在ThirdActivity中
public static void finishAll(){
for (Activity activity:activities) {
if(!activity.isFinishing()){
activity.finish();
}
}
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityCollector.addActivity(this);//向List添加活动
}
@Override
protected void onDestroy() {
super.onDestroy();
ActivityCollector.removeActivity(this);//从List移除活动
}
//销毁所有Activity后可以加上结束当前进程的方法
public void onClick(View v) {
ActivityCollector.finishAll();//销毁所有活动
}