Using intents with Anko
Intents are one of the most common components used in Android apps. They can be thought of as a messenger used to transfer messages between different Android components. For example, you send an intent when you need to start an activity, you send an intent when you need to start a service. To launch an activity in Android, you are first needed to create an intent and then pass it to the startActivity
method. In the following example, we will try to launch an activity with some data and flags:
valintent= Intent(this, SomeActivity::class.java) intent.putExtra("data", 5) intent.setFlag(Intent.FLAG_ACTIVITY_SINGLE_TOP) startActivity(intent)
Also, you can assume an extra line for all data that you pass with the intent.
Anko has a better way to achieve similar results. In this recipe, we will learn how to achieve this (launching intents) using Anko library.
Getting ready
I'll be using Android Studio for coding purpose. You need to include Anko library in your build.gradle
file...