Passing data between activities in Android using intents has minimal impact on frame rate and memory if the data size is small, such as strings or numbers. Large data objects or complex serializable data can increase memory usage and slow down activity transitions, potentially causing jank or dropped frames. Efficient data passing helps maintain smooth 60fps UI and conserves battery life by avoiding heavy processing during navigation.
Passing data between activities in Android Kotlin - Build, Publish & Deploy
- Pass only essential data using intent extras to keep the payload small.
- Use Parcelable instead of Serializable for custom objects to reduce serialization overhead.
- Avoid passing large bitmaps or files; instead, pass references like URIs or file paths.
- Consider using ViewModel or shared data repositories for complex data sharing to reduce intent size.
- Preload or cache data in the receiving activity to speed up UI rendering after navigation.
Passing data between activities does not directly affect the app bundle size. However, including large data classes or heavy serialization libraries can increase APK size. Efficient data passing keeps activity startup fast, reducing perceived load time. Avoid embedding large static data in intents to prevent slow activity launches.
On Android, data is passed between activities using intents with extras. On iOS, data is passed between view controllers typically via segues or direct property setting. Android requires data to be Parcelable or Serializable for intents, while iOS uses native Swift types or Codable. Android's activity lifecycle and intent system differ from iOS's view controller navigation, so data passing patterns are platform-specific.
- Ensure data passed between activities does not expose sensitive user information unintentionally.
- Follow privacy policies by not passing personal data without user consent.
- Keep app responsive during navigation to meet user experience guidelines.
- Do not pass executable code or unsafe data that could cause crashes or security issues.
- Test on multiple devices to ensure smooth transitions and no memory leaks.
Your app takes 5 seconds to load this screen after navigation. What's likely wrong?
- Passing large or complex data objects via intent extras causing slow serialization.
- Loading heavy resources synchronously in the receiving activity's onCreate method.
- Not using Parcelable for custom objects, causing inefficient serialization.
- Passing bitmaps or large files directly instead of references.
Practice
Solution
Step 1: Understand Intent usage
Intent is the standard way to start a new activity and can carry data with putExtra().Step 2: Recognize data passing method
putExtra() attaches key-value pairs to the Intent for the next activity to retrieve.Final Answer:
Use an Intent with putExtra() to attach data. -> Option AQuick Check:
Intent + putExtra() = Data passing [OK]
- Trying to call methods of another activity directly
- Using global variables which is not recommended
- Assuming database is needed for simple data passing
Solution
Step 1: Recall Intent method for extras
putExtra() is the correct method to add data to an Intent.Step 2: Check syntax correctness
putExtra() takes a key and a value as parameters, matching intent.putExtra("username", username).Final Answer:
intent.putExtra("username", username) -> Option CQuick Check:
putExtra() syntax correct = intent.putExtra("username", username) [OK]
- Using non-existent methods like addExtra or setExtra
- Confusing putExtra with putData
- Missing quotes around the key string
val intent = Intent(this, ActivityB::class.java)
intent.putExtra("age", 25)
startActivity(intent)
What code correctly retrieves the "age" integer in Activity B?Solution
Step 1: Identify the data type sent
The value sent is an integer 25, so we must retrieve it as an Int.Step 2: Use correct retrieval method
getIntExtra() retrieves an Int extra with a default fallback value.Final Answer:
val age = intent.getIntExtra("age", 0) -> Option AQuick Check:
Integer extra retrieval = getIntExtra() [OK]
- Using getStringExtra() for an integer value
- Trying to cast getExtra() without safe methods
- Using non-existent getInt() method
val email = intent.getStringExtra("email")!!Solution
Step 1: Understand !! operator risk
Using !! forces a non-null value and crashes if the extra is missing (null).Step 2: Recognize safe retrieval practice
It's safer to check for null or provide a default instead of forcing !!.Final Answer:
Using !! can cause a crash if "email" extra is missing. -> Option BQuick Check:
Unsafe !! usage risks crash [OK]
- Assuming extras always exist without null checks
- Thinking getStringExtra() is invalid
- Confusing keys with resource IDs
Solution
Step 1: Identify correct method for List<Int>
Intent supports ArrayList<Int> via putIntegerArrayListExtra() and getIntegerArrayListExtra().Step 2: Confirm retrieval matches sending method
Using these methods ensures type safety and proper data transfer.Final Answer:
Use intent.putIntegerArrayListExtra("userIds", ArrayList(userIds)) and retrieve with getIntegerArrayListExtra("userIds") -> Option DQuick Check:
Use put/getIntegerArrayListExtra for List<Int> [OK]
- Trying to send List<Int> directly with putExtra()
- Using getIntExtra() for a list
- Using static variables which breaks encapsulation
Ready to prove it?
Pass the test and this pattern moves unknown
