Skip to content

Instantly share code, notes, and snippets.

@hi-manshu
Created January 8, 2021 06:49
Show Gist options
  • Save hi-manshu/e9d4f4fd4fc997743d243a480c15c473 to your computer and use it in GitHub Desktop.
Save hi-manshu/e9d4f4fd4fc997743d243a480c15c473 to your computer and use it in GitHub Desktop.
inline fun <reified T : Any> Activity.launchActivity(
requestCode: Int = -1,
options: Bundle? = null,
noinline init: Intent.() -> Unit = {}) {
val intent = newIntent<T>(this)
intent.init()
startActivityForResult(intent, requestCode, options)
overridePendingTransition(R.anim.slide_up, R.anim.no_change)
}
inline fun <reified T : Any> Fragment.launchActivity(
requestCode: Int = -1,
options: Bundle? = null,
noinline init: Intent.() -> Unit = {}) {
val intent = newIntent<T>(requireContext())
intent.init()
startActivityForResult(intent, requestCode, options)
requireActivity().overridePendingTransition(R.anim.slide_up, R.anim.no_change)
}
inline fun <reified T : Any> Activity.launchActivity(
options: Bundle? = null,
noinline init: Intent.() -> Unit = {}) {
val intent = newIntent<T>(this)
intent.init()
startActivity(intent, options)
overridePendingTransition(R.anim.slide_up, R.anim.no_change)
}
inline fun <reified T : Any> Fragment.launchActivity(
options: Bundle? = null,
noinline init: Intent.() -> Unit = {}) {
val intent = newIntent<T>(requireContext())
intent.init()
startActivity(intent, options)
requireActivity().overridePendingTransition(R.anim.slide_up, R.anim.no_change)
}
inline fun <reified T : Any> newIntent(context: Context): Intent =
Intent(context, T::class.java)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment