Skip to content

Instantly share code, notes, and snippets.

@useataaaaa
Created October 13, 2019 14:49
Show Gist options
  • Select an option

  • Save useataaaaa/3e30d9886d08dd51c293cd17ae42cf79 to your computer and use it in GitHub Desktop.

Select an option

Save useataaaaa/3e30d9886d08dd51c293cd17ae42cf79 to your computer and use it in GitHub Desktop.
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
inline fun <reified T : Any> Context.launchActivity(
options: Bundle? = null,
noinline init: Intent.() -> Unit = {}) {
val intent = newIntent<T>(this)
intent.init()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
startActivity(intent, options)
} else {
startActivity(intent)
}
}
inline fun <reified T : Any> newIntent(context: Context): Intent =
Intent(context, T::class.java)
@useataaaaa
Copy link
Copy Markdown
Author

how to use :

launchActivity<UserDetailActivity> { putExtra(INTENT_USER_ID, user.id) }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment