I want to call startActivityforResult
in a one line statement in Kotlin. Something like this:
startActivityForResult(Intent(this@MainActivity2,MainActivity::class.java),1))
Option 1: Use Anko library:
startActivityForResult<MainActivity>(1)
Option 2: You can create your own extension Function on Activity or AppCompactActivity:
inline fun <reified T: Activity> Activity.myStartActivityForResult(requestCode: Int) {
val intent = Intent(this, T::class.java)
startActivityForResult(intent, requestCode)
}
myStartActivityForResult<MainActivity>(1)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With