🚀 Launching Activities in Easier Way Using Kotlin Extensions 💻

Kotlin Extensions for simpler, easier and fun way of launching Activities in Android

Reposted on my Medium profile.

Few days ago, I was reading this awesome article by Elye about a Kotlin keyword reified . Soon after reading the article, I started exploring it and I realized that we can simply lots of reusable tasks of Android development using reified and Kotlin extension methods. For example, launching Activities.


🔲 Launching Activities — Traditional Way

Launching activities in android apps is a common task and different developers use different approaches. Some use the traditional ways of creating Intent bundles and passing them in startActivity() methods along side the Intents.

Let’s look at the typical traditional way of starting another activity

Now, if we pass some arguments in it, this becomes more complex.


💥 Launching Activities —The Simpler, Easier, and Fun Way

But, creating some Kotlin extension methods with using reifiedkeyword, we can make these a lot simpler and enjoyable.

GitHub Gist: [https://gist.github.com/wajahatkarim3/d3a728dbb20002dc54ac44bad40e4077](https://gist.github.com/wajahatkarim3/d3a728dbb20002dc54ac44bad40e4077)

Now, after this, we can do same launching activity stuff (of previous examples) like this:

Or we can pass arguments like this:

Here are all the cases which you can do with these extensions:


Codes available in following Gists:



If you liked this article, you can read my new articles below:


Wajahat Karim is Pakistan’s first Google Developer Expert in Android. As an experience Android developer, he deeply cares about it and keeps writing and speaking about it. He has written two worldwide 300+ pages books on Android development with more than 100 articles around the internet either on his website or his Medium publications. He is also a passionate contributor in open source and has created many Android libraries used by thousands of developers in their apps worldwide. As active public speaker, he spends lots of time giving talks in conferences and motivating people on Android development. You can find Wajahat most active on Twitter @WajahatKarim where he regularly shares all the good stuff about Android and community building.

Author's picture

Wajahat Karim

🔥 Google Dev Expert (GDE) in Android .
📱 Android Dev. 💻 Open Source Contributor . 📝 Technical Writer . 🎤 Public Speaker

Senior Android Developer

Karachi, Pakistan