Instruction

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

The Purpose of Passing Data to Other Apps

Consider a real-world example to understand the need to pass data to other apps. Assume you plan to watch a movie in a nearby cinema with your friends, and you book the tickets using an app. When you’ve booked the tickets, you might want to share the booking details such as the film’s name and show time, the cinema’s location, etc., with your friends.

Passing Data Outside Your App

To pass data outside your app, you must use an Intent. You use an Intent in Android to tell the system to perform some action from a component of the same or different app(s); the most common one is to start an Activity. Intents are of various types and can perform different actions based on their action type.

import android.content.Intent

val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_SUBJECT, "Booking Details for Inside Out")
intent.putExtra(Intent.EXTRA_TEXT, "You have booked 2 tickets for Inside Out - 9:30pm at Greenwich Cinema")
context.startActivity(
  Intent.createChooser(
    intent,
    "Movie booking details"
  )
)
context.startActivity(intent)
See forum comments
Download course materials from Github
Previous: Introduction Next: Demo