Skip to content

Instantly share code, notes, and snippets.

@prbale
Created December 10, 2017 16:29
Show Gist options
  • Save prbale/0a9c2ca98e64c4b4d692f88a376944f1 to your computer and use it in GitHub Desktop.
Save prbale/0a9c2ca98e64c4b4d692f88a376944f1 to your computer and use it in GitHub Desktop.
Starting Activity in Kotlin
class AccountDetailsActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val accountNumber = intent.getStringExtra(ACCOUNT_NUMBER)
?: throw IllegalStateException("ACCOUNT_NUMBER is mandatory in the Intent")
}
companion object {
private val ACCOUNT_NUMBER = "ACCOUNT_NUMBER"
fun newIntent(context: Context, accountNumber: String): Intent {
val intent = Intent(context, AccountDetailsActivity::class.java)
intent.putExtra(ACCOUNT_NUMBER, accountNumber)
return intent
}
}
}
class CallingActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
accountList.clickListener { account ->
val intent = UserDetailActivity.newIntent(this, account.accountNumber)
startActivity(intent)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment