-
-
Save hichamboushaba/0234bc6f089df5fdbd3228dc9c530ebd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ActivityProvider : Application.ActivityLifecycleCallbacks { | |
private var _currentActivity = WeakReference<ComponentActivity>(null) | |
val currentActivity | |
get() = _currentActivity.get() | |
fun init(application: Application) = application.registerActivityLifecycleCallbacks(this) | |
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {} | |
override fun onActivityStarted(activity: Activity) { | |
(activity as? ComponentActivity)?.let { | |
_currentActivity = WeakReference(it) | |
} | |
} | |
override fun onActivityResumed(activity: Activity) { | |
(activity as? ComponentActivity)?.let { | |
_currentActivity = WeakReference(it) | |
} | |
} | |
... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment