I was developing an Android app and in one of the sections, I pass data using an Intent from a DatePicker dialog fragment back to the fragment that created it using getTargetFragment().onActivityResult(int targetRequestCode, int resultCode, Intent intent). I am adding three integers (date, month and year) extracted from the Calendar fragment to the intent being passed. And then I read this intent within the onActivityResult() method of the fragment that created it. Everything works as it should and all is fine and dandy and the world is a perfect place to live in.
While I was trying to debug a silly error that I had made, I noticed something interesting. When I expand the content of the intent, I find that my data is in a bundle as expected. But I see that there is another object within the intent called android.util.ArrayMap with size 3.
This size seems to correspond to the number of data that I put in the intent (I tested it by adding additional dummy parameters). when I expand the contents of the ArrayMap, I see that it throws a ClassNotFoundException. Why would it do this. The key type is String and the value type is Integer (I am putting an int but I don't think it matters as I added in String for key and value and it still threw the exception). I expanded the ArrayMap details but it did not seem to make sense.
My questions are:
- Why is this ClassNotFoundException happening?
- What is the need for the ArrayMap in the first place?
your
putExtra
values are saved insideBundle
's internal data structure , which happens to beArrayMap
Here is its definition, declared in
Bundle.java
sourceI guess it converts your
int
to a more genericObject
class.ClassNotFoundException
could be IDE/debug window issue, as there is not any other custom class here for this data structure. Also, you are expected to use package-name prefix in yourname
, as mentioned here