package jackall.moncalc import android.annotation.SuppressLint import android.app.Activity import android.app.Application import android.os.Bundle /** * Created by matsumoto_k on 2017/11/01. */ class App : Application() { var currentActivity: Activity? = null companion object { @SuppressLint("StaticFieldLeak") lateinit var instance: App private set } override fun onCreate() { super.onCreate() instance = this registerActivityLifecycleCallbacks(object : Application.ActivityLifecycleCallbacks { override fun onActivityCreated(activity: Activity, saveInstanceState: Bundle?) { } override fun onActivityStarted(activity: Activity) { currentActivity = activity } override fun onActivityResumed(activity: Activity) { } override fun onActivityPaused(activity: Activity) { } override fun onActivityStopped(activity: Activity) { if (currentActivity === activity) { currentActivity = null } } override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) { } override fun onActivityDestroyed(activity: Activity) { } }) } }