Created
July 9, 2019 18:50
-
-
Save fo2rist/91028a333dce2ae63cd7e05f2e35fc8b to your computer and use it in GitHub Desktop.
ActivityThatMayCrash.kt
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 SomeStrictActivity : Activity() { | |
companion object { | |
@JvmStatic | |
fun createIntent(context: Context, importantParameter: Parameter): Intent { | |
val intent = Intent(context, SomeStrictActivity::class.java) | |
intent.putExtra(EXTRA_PARAMETER, importantParameter) | |
return intent | |
} | |
} | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val parameter = intent.getSerializableExtra(EXTRA_PARAMETER) | |
// if launched properly this should never happen, so it's OK to crash when getSerializableExtra gives null | |
?: throw IllegalArgumentException("Required parameter $EXTRA_PARAMETER is missing in the intent.") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment