What is the difference of these 2 values, if both of them transmit data according to the key-value scheme?
1 answer
Bundle is a type-safe container aimed at reading and writing data and its purpose is to store and provide certain information on the key-value type, where the key is a string and values ​​are data implementing the Parcelable interface or inheriting the Parcel class, which in turn provide the opportunity for data packing / unpacking during inter- stream communication (data exchange between multiple threads). It is important to note that it is the implementation of Parcelable for Bundle values ​​that provides the ability to pack / unpack an object, roughly speaking, this means that you do not need a strict binding to the memory block that the instance uses, since this instance can be recreated. For this, the values ​​must implement the Parcelable interface. The type safety of a Bundle provided by its method of setting / getting values, which provides access to types only by strictly defined, permissible methods. This means that by “putting” a value in the Bundle using the putShort() method, you can only get this value using the getShort() method. The result is that the Bundle is a kind of HashMap "sharpened" to work with IPC (Inter-Process Communication).
In turn, JsonObject is a mutable set of name / value pairs, like Bundle . Names must be unique, not null strings, unlike Bundle which can take on null values, and the "non-unique" name (key) will simply overwrite the existing key-value pair. Values ​​can be a mix from JSONObject , JSONArray , String , Boolean , Integer , Long , Double or JsonObject.NULL . Values ​​cannot be null, NaNs, and so on. and can take values only above listed types. Instances of this class are not thread safe . In essence, this is a class implemented to use the JSON protocol.
After carefully reading the features described above, it becomes obvious that Bundle and JsonObject although similar to surfaces, have nothing in common with their destination.
- The answer is good, only now you understand that such a question as this would hardly have been asked by a professional? And you got the answer like from a book on scientific literature)) I didn’t understand half)) you can clarify that it was clear. 1) What is a 'type safe container', 2) 'inter-thread communication'? 3) You write that "JsonObject is a mutable pair of pairs", then Bundle is not a mutable chunk? 4) Names must be unique, not null strings for a JsonObject, so I understood that for a Bundle it is not necessary? - Aleksey Timoshchenko
- @Aleks Completed the answer, tried to answer your questions. - Stas Lelyuk