package com.baoshi.swms;

import android.app.Activity;

import java.lang.ref.WeakReference;

/**
 * 获取当前Activity 这将在子进程调用UI时使用
 *
 * @author Zhendong Zhou
 * @date 2021/12/3 16:45
 */
public class MyActivityManager {
    private static final MyActivityManager sInstance = new MyActivityManager();
    private WeakReference<Activity> sCurrentActivityWeakRef;


    private MyActivityManager() {

    }

    public static MyActivityManager getInstance() {
        return sInstance;
    }

    public Activity getCurrentActivity() {
        Activity currentActivity = null;
        if (sCurrentActivityWeakRef != null) {
            currentActivity = sCurrentActivityWeakRef.get();
        }
        return currentActivity;
    }

    public void setCurrentActivity(Activity activity) {
        sCurrentActivityWeakRef = new WeakReference<Activity>(activity);
    }
}
