Skip to content

Instantly share code, notes, and snippets.

@piotrmadry
Last active January 1, 2019 20:59
Show Gist options
  • Save piotrmadry/9293adb78e4700431140d0310b6644c1 to your computer and use it in GitHub Desktop.
Save piotrmadry/9293adb78e4700431140d0310b6644c1 to your computer and use it in GitHub Desktop.
inline fun <reified T : Activity> Context.open() = startActivity(Intent(this, T::class.java))
inline fun <reified T : Activity> Context.openForResult(code: Int) = startActivityForResult(Intent(this, T::class.java), code)
inline fun <reified T : Fragment> newInstance(): T = T::class.java.newInstance()
Usage:
open<LoginActivity>()
openForResult<LoginActivity>(INTENT_CODE)
supportFragmentManager
.beginTransaction()
.replace(R.id.login_fragment_container, newInstance<LoginFragment>())
.commit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment