How Android Intent putExtra() work? Under the hood …

Kamaldeep Kumar
2 min readApr 26, 2021

--

Today we will discuss some basic points about intent putExtra(), How internally it works, and which data structure is used for it?

Photo by Timon Studler on Unsplash
val intent = Intent(this, SecondActivity::class.java)
intent.putExtra("k","v")
startActivity(intent)
  1. When we write intent.putExtra(“k”,”v”) and click on this function
public @NonNull Intent putExtra(String name, @Nullable String value) {
if (mExtras == null) {
mExtras = new Bundle();
}
mExtras.putString(name, value);
return this;
}

we see that it creates a Bundle object and adds it into mExtras.putString(name, value); and mExtras which is a bundle object, defines the global of the Intent class

Bundle mExtras;

after this we see mExtras.putString(name, value); is used to store name values,

when we click on mExtras.putString(name, value);

public void putString(@Nullable String key, @Nullable String value) {
unparcel();
mMap.put(key, value);
}

here we observe mMap.put(key, value); and mMap is ArrayMap<K,V> data structure that is designed to be more memory efficient than the traditional HashMap<K,V>

ArrayMap<String, Object> mMap = null;

Points To Remember

  1. The Bundle object is created when putExtra() is used.
  2. Internally ArrayMap<K,V> data structure is used to store data.

Kindly clapping …

--

--