Junior — Middle
How is data stored inside a Bundle in Android?
sobes.tech AI
Answer from AI
In Android, the Bundle class is used for storing and passing data between components (for example, between an Activity or Fragment). Inside a Bundle, data is stored as key-value pairs, where the key is a string and the value is an object of a specific type.
Bundle is implemented based on an internal structure similar to a dictionary (Map), which serializes data for transfer.
Primitive types (int, boolean, float, etc.) are supported, as well as objects that implement the Parcelable or Serializable interfaces.
Example of usage:
Bundle bundle = new Bundle();
bundle.putString("username", "user123");
bundle.putInt("age", 25);
String username = bundle.getString("username");
int age = bundle.getInt("age");
Thus, Bundle serves as a container for temporary storage and data transfer during the application's lifecycle.