Created
May 22, 2019 17:18
-
-
Save polson/b5a3edad97119764bfd0a8cc1d60cddb to your computer and use it in GitHub Desktop.
Method to get an activity instance from a context
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
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