package com.wasu.cs.utils;

import android.app.Activity;

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

public class ActivityManager {

    private static final String TAG = ActivityManager.class.getSimpleName();

    private List<Activity> mActivities = new ArrayList<Activity>();


    private ActivityManager() {

    }


    private static class ActivityManagerHolder {
        static private ActivityManager instance = new ActivityManager();
    }


    public static ActivityManager getInstance() {

        return ActivityManagerHolder.instance;
    }


    public void removeActivity(Activity activity) {
        mActivities.remove(activity);
    }


    public void addActivity(Activity activity) {
        mActivities.add(activity);
    }

    public List<Activity> getActivityList() {
        return mActivities;
    }

    public void exitApp() {
        try {
            for (Activity activity : mActivities) {
                if (activity != null)
                    activity.finish();
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            android.os.Process.killProcess(android.os.Process.myPid());
            System.exit(0);
        }
    }

}
