Are android bundles functionally equivalent to maps?
I’m looking for a way to convert a bundle to a HashMap. I’m surprised that this method is not available in docs .
Is a bundle equivalent to a Map with string keys and object values? Is it theoretically possible to convert to a map? Is there any way to do this?
Edit: Is the relationship between key and value clear in the bundle?
Solution
Is not the Bundle equivalent of a Map, where you have String keys and Object values?
First, a does not necessarily haveString
a Map
key.
Second, at the same time Map
can hold arbitrary objects, which it cannot do so in a type-safe manner. IOW, if you want Map
to save strings, integers, etc., you need to continue converting get()
the results. Phone, because your Map
must be Map<String, Object>
.
Third, tools Parcelable
,Bundle
which are very important for Android IPC. Map
is an interface and does not extend Parcelable
.
Can it be theoretically converted to a mapping?
Well, of course, although I don’t see any benefit.
What is the way to do this?
Iterate keySet()
through and callget()
on Bundle
for each key, put the result into Map<String, Object>
the .