package com.develop.food.base.utils

import android.app.Activity
import android.app.Application
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import java.lang.ref.WeakReference

/**
 * Create by lwh on 2022/8/4
 */
object TopResumedActivityHolder : Application.ActivityLifecycleCallbacks {

    private var ref: WeakReference<AppCompatActivity>? = null

    fun getCurrentActivity(): AppCompatActivity? {
        return ref?.get()
    }

    override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {

    }

    override fun onActivityStarted(activity: Activity) {

    }

    override fun onActivityResumed(activity: Activity) {
        if (activity is AppCompatActivity){
            ref = WeakReference(activity)
        }
    }

    override fun onActivityPaused(activity: Activity) {

    }

    override fun onActivityStopped(activity: Activity) {

    }

    override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {

    }

    override fun onActivityDestroyed(activity: Activity) {

    }
}