Can anyone share their goto approach for Intent di...
# android
a
Can anyone share their goto approach for Intent dispatching using Kotlin? I've seen Context Extensions for instance
Context.startParticularScreen(intentParams)
but that seems wrong given it's an extension on such a global object
p
For activities specifically, https://medium.com/@passsy/starting-activities-with-kotlin-my-journey-8b7307f1e460 compares a couple different ideas with varying levels of cleverness. I tend toward a variation of the
newIntent()
strategy that starts the new activity right inside the function, kind of like:
Copy code
companion object {
        private val SOME_PARAMETER = "user_id"

        fun start(activity: Activity, param: Param) {
            val intent = Intent(activity, SomeActivity::class.java)
            intent.putExtra(SOME_PARAMETER, param)
            activity.startActivity(intent)
        }
    }
which makes the call site look like:
Copy code
SomeActivity.start(this, param)
Would love to hear what other people are doing too!