Skip to content

Instantly share code, notes, and snippets.

@polson
Created May 22, 2019 17:18
Show Gist options
  • Save polson/b5a3edad97119764bfd0a8cc1d60cddb to your computer and use it in GitHub Desktop.
Save polson/b5a3edad97119764bfd0a8cc1d60cddb to your computer and use it in GitHub Desktop.
Method to get an activity instance from a context
private fun scanForActivity(context: Context?): FragmentActivity? = when (context) {
is FragmentActivity -> context
is ContextWrapper -> scanForActivity(context.baseContext)
else -> throw IllegalArgumentException("Context must be a FragmentActivity!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment