package com.pxkj.jwzs;

import android.app.Activity;
import android.util.Log;

import com.acrabsoft.sdk.AppStoreApplication;


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

/**
 * Created by 皮蛋 on 2021/9/15.
 */

public class MyApplication extends AppStoreApplication {


    public static List<Activity> activitys = new ArrayList<>();

    private static MyApplication instance;

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        registerActivityLifecycleCallbacks(new MyLifecycleHandler(MyApplication.this));
    }

    public  static MyApplication getInstance() {
        return instance;
    }

    public static void finishAll(){
        if(activitys!=null){
            Log.e("MyApplication", "activitys -->"+activitys.size());

            Iterator<Activity> iterator = activitys.iterator();
            while(iterator.hasNext()){
                Activity activity = iterator.next();
                activity.finish();
                iterator.remove();   //注意这个地方
            }
        }

    }
}
