Skip to content

Instantly share code, notes, and snippets.

@yongjhih
Last active August 16, 2023 11:45
Show Gist options
  • Save yongjhih/e42352ccdb4cc5668d2b0660058563c3 to your computer and use it in GitHub Desktop.
Save yongjhih/e42352ccdb4cc5668d2b0660058563c3 to your computer and use it in GitHub Desktop.
@JvmName("getActivityInternal")
internal tailrec fun Context.getActivity(): Activity? =
this as? Activity
?: (this as? ContextWrapper)?.baseContext?.getActivity()
val Context.activity: Activity? get() = getActivity()
val View.activity: Activity? get() = context.getActivity()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment