Starting an activity made easy

Tell me, how many times have you used the following code to start an Activity?

    Intent intent = new Intent(CurrentActivity.this,       NextActivity.class);    intent.putExtra("key", value); //Optional parameters    CurrentActivity.this.startActivity(intent);

Countless times, isn't it? And we know it's boring. But now with the help of Anko, we can start activity very easily. Anko's Intents.kt has a few extension functions using which we can start the activity. Take a look at the code in AppToolbar.kt, on clicking the menu we are starting ProfileActivity:

    toolbar.context.startActivity<ProfileActivity>()

The code looks so much cleaner with no verbosity. But starting an activity is not always that simple. We also sometimes ...

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.