Skip to content

Instantly share code, notes, and snippets.

@passsy
Last active February 16, 2017 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save passsy/34f99d5a57e331e872b88cc1fae25dc0 to your computer and use it in GitHub Desktop.
Save passsy/34f99d5a57e331e872b88cc1fae25dc0 to your computer and use it in GitHub Desktop.
class UserDetailActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val userId = intent.getStringExtra(INTENT_USER_ID)
?: throw IllegalStateException("field $INTENT_USER_ID missing in Intent")
}
companion object {
private val INTENT_USER_ID = "user_id"
fun newIntent(context: Context, user: User): Intent {
val intent = Intent(context, UserDetailActivity::class.java)
intent.putExtra(INTENT_USER_ID, user.id)
return intent
}
}
}
class OtherActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//...
userlist.clickListener { user ->
val intent = UserDetailActivity.newIntent(this, user)
startActivity(intent)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment