Skip to content

Instantly share code, notes, and snippets.

@jknair0
Last active August 18, 2019 13:10
Show Gist options
  • Select an option

  • Save jknair0/c7a528b65c7258597510f4a185bbd6fa to your computer and use it in GitHub Desktop.

Select an option

Save jknair0/c7a528b65c7258597510f4a185bbd6fa to your computer and use it in GitHub Desktop.
android context extension functions
inline fun <reified T : AppCompatActivity> Context.startActivity(intentExtras: Intent.() -> Unit = {}) {
startActivity(Intent(this, T::class.java).apply {
this.intentExtras()
})
}
fun Context.inflate(
@LayoutRes layoutRes: Int, root: ViewGroup? = null,
attachToParent: Boolean = false
): View {
return LayoutInflater.from(this).inflate(layoutRes, root, attachToParent)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment