package com.ama.core.architecture


import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.res.Configuration
import java.lang.ref.WeakReference

abstract class BaseApp : Application() {

    companion object {
        private var currentActivity: WeakReference<Activity>? = null

        fun setCurrentActivity(activity: Activity?) {
            currentActivity = if (activity == null) null else WeakReference(activity)
        }

        fun getCurrentActivity(): Activity? {
            return currentActivity?.get()
        }
        private lateinit var instance: BaseApp
        fun appContext(): Context = instance
    }



    override fun onCreate() {
        super.onCreate()
        instance = this
    }

    override fun onTerminate() {
        super.onTerminate()
    }

    // 系统资源配置发生更改回调，例如主题模式，需要重新刷新多语言
    override fun onConfigurationChanged(newConfig: Configuration) {
        super.onConfigurationChanged(newConfig)
    }

}