Skip to content

Instantly share code, notes, and snippets.

@jraska
Last active March 18, 2020 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jraska/b86f020095157f21503bee502d847b69 to your computer and use it in GitHub Desktop.
Save jraska/b86f020095157f21503bee502d847b69 to your computer and use it in GitHub Desktop.
class TopActivityProvider {
var topActivity: Activity? = null
private set
private val callbacks: Application.ActivityLifecycleCallbacks = object : ActivityLifecycleCallbacks {
override fun onActivityResumed(activity: Activity) {
topActivity = activity
}
override fun onActivityPaused(activity: Activity) {
topActivity = null
}
// Other methods are empty
}
private fun setupWith(app: Application) {
app.registerActivityLifecycleCallbacks(callbacks)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment