0
0
Android Kotlinmobile~5 mins

Passing arguments in Android Kotlin - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of passing arguments between Android activities?
Passing arguments allows one activity to send data to another activity, enabling communication and data sharing between screens.
Click to reveal answer
beginner
How do you pass a simple string argument from one activity to another in Kotlin?
Use an Intent to start the new activity and add the string with putExtra(key, value). For example: intent.putExtra("username", "Alice").
Click to reveal answer
beginner
How do you retrieve a passed argument in the receiving activity?
In the receiving activity, use intent.getStringExtra(key) or the appropriate get method to get the data sent from the previous activity.
Click to reveal answer
intermediate
What is a Bundle in Android, and how is it related to passing arguments?
A Bundle is a container for key-value pairs used to pass data between activities or fragments. Intents use Bundles internally to carry extras.
Click to reveal answer
beginner
Why should you use constants for keys when passing arguments?
Using constants for keys avoids typos and makes code easier to maintain and understand, ensuring the same key is used when putting and getting data.
Click to reveal answer
Which method is used to add data to an Intent for passing arguments?
AgetExtra()
BstartActivity()
CputExtra()
DsetContentView()
How do you retrieve a string argument named "user" in the receiving activity?
AgetIntent().putExtra("user")
Bintent.putExtra("user")
CstartActivity(intent)
Dintent.getStringExtra("user")
What is the role of a Bundle in passing arguments?
AIt stores key-value pairs of data to pass between components
BIt starts a new activity
CIt displays UI elements
DIt manages app permissions
Why is it recommended to use constants for keys when passing arguments?
ATo change UI colors
BTo avoid typos and keep keys consistent
CTo reduce app size
DTo increase app speed
Which of these is NOT a valid way to pass arguments in Android?
AUsing SharedPreferences for temporary data transfer
BUsing Bundles
CUsing Intent extras
DUsing startActivityForResult with Intent extras
Explain how to pass a string argument from one Android activity to another using Kotlin.
Think about how you send data with an Intent and retrieve it in the new screen.
You got /5 concepts.
    Describe why using constants for keys when passing arguments is a good practice.
    Consider what happens if you mistype a key in one place.
    You got /4 concepts.