Listing all extras of an Intent
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Android Intent extras are stored in a Bundle, which means you can inspect them dynamically instead of fetching each key by hand. That is especially useful when debugging deep links, broadcast receivers, and activity launches where you are not fully sure what another component attached.
The Basic Way to List All Extras
The core API is intent.extras, which returns a Bundle?. From there, iterate through keySet() and read each value.
This works for quick inspection because Bundle.get returns Any?, which is enough for logging and debugging.
A More Complete Debug Helper
In real applications, a helper function is better than repeating the loop in every activity.
Usage:
Logging both the value and the runtime type makes debugging much easier when different callers pass different data shapes.
Handling Typed Values Correctly
For inspection, extras.get(key) is fine. For application logic, keep using the typed getters such as getString, getInt, and getBoolean.
The difference matters because typed getters express intent and provide default handling. A debug dump should be generic, but business logic should not depend on raw Any? access unless that is truly necessary.
Extras Can Contain More Than Strings
A Bundle can hold many kinds of values:
- Primitive values such as
Int,Boolean, andLong. - Strings and string arrays.
- '
Parcelableobjects.' - '
Serializableobjects.' - Nested
Bundlevalues.
If you want a more readable debug dump, handle nested Bundle values explicitly:
That is useful when extras contain structured payloads instead of flat keys.
Logging Extras From Incoming Deep Links and Broadcasts
This technique is not limited to activities. The same pattern works in services, broadcast receivers, and fragments that receive arguments converted from an intent.
For a BroadcastReceiver:
For debugging external integrations, this is often faster than guessing which keys another app uses.
Why Null Checks Matter
intent.extras can be null. Even if you expect extras, defensive checks are still worth it because:
- The activity may have been launched from a different path.
- A deep link may omit optional parameters.
- An integration may change over time.
A missing Bundle is normal in many flows, so treat it as a valid case rather than as an exception.
Common Pitfalls
- Assuming every intent has extras and skipping the null check.
- Using the generic
Bundle.getvalues for application logic instead of typed getters. - Forgetting that complex objects may be
Parcelableor nestedBundlevalues. - Logging extras in production builds without thinking about sensitive information.
- Debugging only the expected keys and missing a typo or alternate key name sent by another component.
Summary
- Intent extras live inside a
Bundleand can be listed by iterating overkeySet(). - '
Bundle.get(key)is useful for debugging, while typed getters are better for application logic.' - A reusable helper makes intent inspection much easier across activities and receivers.
- Nested bundles and parcelables may require slightly richer logging.
- Always null-check
intent.extras, because missing extras are a normal runtime case.

