Created
December 10, 2017 16:29
-
-
Save prbale/0a9c2ca98e64c4b4d692f88a376944f1 to your computer and use it in GitHub Desktop.
Starting Activity in Kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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