Launching Activities in Easier Way Using Kotlin Extensions
Tags: java, android, kotlin, mobile
Published: 2019-07-02 08:26:54

---
title: Launching Activities in Easier Way Using Kotlin Extensions
published: true
tags: java,android,kotlin,mobile
canonical_url: https://wajahatkarim.com/2019/03/-launching-activities-in-easier-way-using-kotlin-extensions-/
---

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

![Related image](https://cdn-images-1.medium.com/proxy/1*99YiKjwB2TliKVA-yGogNQ.png)

> Originally published on [https://wajahatkarim.com](https://wajahatkarim.com)

Few days ago, I was reading [this awesome article](https://proandroiddev.com/how-reified-type-makes-kotlin-so-much-better-7ae539ed0304) by [Elye](https://medium.com/u/5742b4fcf89e) 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

![](https://cdn-images-1.medium.com/max/1024/1*OP2pPLfWAkBf4yz9Pk-3JQ.png)

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

![](https://cdn-images-1.medium.com/max/1024/1*AbOP2ToC0QBCm4fg3yzABw.png)

***

### 💥 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.

![](https://cdn-images-1.medium.com/max/1024/1*y76gedjcWjVmnlb7ntbRjQ.png)<figcaption>GitHub Gist: <a href="https://gist.github.com/wajahatkarim3/d3a728dbb20002dc54ac44bad40e4077">https://gist.github.com/wajahatkarim3/d3a728dbb20002dc54ac44bad40e4077</a></figcaption>

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

![](https://cdn-images-1.medium.com/max/980/1*7J0f0hn4jd82kr36eQFu4Q.png)

Or we can pass arguments like this:

![](https://cdn-images-1.medium.com/max/946/1*D0nesrZqnmB6QrSaiaVcJQ.png)

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

![](https://cdn-images-1.medium.com/max/1024/1*Ym9akomr7goLLVTBNqaFlw.png)<figcaption>Github Gist: <a href="https://gist.github.com/wajahatkarim3/d3a728dbb20002dc54ac44bad40e4077">https://gist.github.com/wajahatkarim3/d3a728dbb20002dc54ac44bad40e4077</a></figcaption>

***

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

- [⚡ Is Your Android Studio Always Slow? 🚀Here’s How to Speed Up Immediately.](https://dev.to/wajahatkarim/-is-your-android-studio-always-slow-heres-how-to-speed-up-immediately-4fi1)
- [📆 Reflections on 2018 — My Year In Review](https://dev.to/wajahatkarim/reflections-on-2018my-year-in-review-144)

***

**Wajahat Karim** is a graduate from [NUST, Islamabad](http://nust.edu.pk), an experienced mobile developer, an active open source contributor, and co-author of two books [Learning Android Intents](https://www.amazon.com/Learning-Android-Intents-Muhammad-Usama/dp/1783289635) and [Mastering Android Game Development with Unity](https://www.amazon.com/Mastering-Android-Game-Development-Unity/dp/1783550775/). In his spare time, he likes to spend time with his family, do experiments on coding, loves to write about lots of things (mostly on [his blog](https://wajahatkarim.com)and medium) and is passionate contributor to open source. In June 2018, one of his library became #1 on [Github Trending](https://github.com/trending). [His libraries](http://github.com/wajahatkarim3) have about 3000 stars on Github and are being used in various apps by the developers all around the globe. Follow him on [Twitter](https://twitter.com/wajahatkarim) and [Medium](https://medium.com/@wajahatkarim3) to get more updates about his work in Writing, Android and Open Source.

* * *