0
0
Android Kotlinmobile~10 mins

Passing data between activities in Android Kotlin - UI Render Trace

Choose your learning style9 modes available
Component - Passing data between activities

This UI component demonstrates how to send data from one screen (activity) to another in an Android app using Kotlin. It shows a simple form where you enter text, press a button, and the next screen displays the entered text.

Widget Tree
Activity1 (MainActivity)
├── EditText (input field)
└── Button (send data)

Activity2 (DisplayActivity)
└── TextView (shows received data)
The first screen (MainActivity) has an input box and a button arranged vertically. When the button is clicked, it opens the second screen (DisplayActivity), which shows the text sent from the first screen.
Render Trace - 3 Steps
Step 1: MainActivity
Step 2: Button (in MainActivity)
Step 3: DisplayActivity
State Change - Re-render
Trigger:User types text in EditText and clicks the Send button
Before
MainActivity shows empty input field; DisplayActivity not started
After
DisplayActivity opens showing the text entered in MainActivity
Re-renders:DisplayActivity UI rebuilds to show the passed data; MainActivity remains unchanged
UI Quiz - 3 Questions
Test your understanding
How does MainActivity send data to DisplayActivity?
ABy directly modifying DisplayActivity's TextView
BBy putting data into Intent extras before starting DisplayActivity
CBy saving data in a global variable
DBy using a database to share data
Key Insight
Passing data between activities in Android is done by attaching data to an Intent as extras. This keeps screens independent and allows smooth data transfer. Always use Intent extras for small data like strings or numbers to keep your app simple and responsive.