

package com.example.lzz.lightplayer.base;

import android.app.Activity;
import android.os.Handler;

import com.example.lzz.lightplayer.activities.MainActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * activity管理类
 * Created by fwingy on 2017/2/10.
 */

public class ActivitiesCollecter {
    public static List<Activity> activities = new ArrayList<>();

    /**
     * 在avtivity创建时（onCreate）调用
     * @param activity 创建的activity
     */
    public static void addActivities(Activity activity) {
        activities.add(activity);
    }

    /**
     * 在avtivity摧毁时（onDestroy）调用
     * @param activity 移除的activity
     */
    public static void removeActivities(Activity activity) {
        activities.remove(activity);
    }

    /**
     * 调用以随时退出程序
     */
    public static void finishAllActivities() {
        for (Activity activity : activities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }


        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                System.exit(0);
            }
        }, 250);
    }
}
