• Why did Andorid design bundles instead of using maps directly
  1. BundleInside is made ofArrayMapThe implementation,ArrayMapThe internal implementation is two arrays, oneintArrays store object data corresponding to subscripts, an array of objects storekeyvalueFor internal usedichotomykeySort, so when you’re adding, when you’re deleting, when you’re looking up data, it’s all useddichotomySearch, only suitable for small data volume operations, if the data volume is relatively large, then its performance will degrade. whileHashMapThe internal isArray + linked listStructure, when the amount of data is low,HashMaptheEntry ArrayArrayMapTake up more memory than useBundleMost of the scenarios are of small data volume, and are usedArrayMapStoring data has advantages in both operation speed and memory footprint, so using bundles to transfer data ensures higher speed and lower memory footprint.
  2. Another reason, however, is thatAndroidIf you useIntentTo carry data, it needs to be a primitive type or a serializable type,HashMapuseSerializableTo serialize, andBundleIs the useParcelableTo serialize, while inAndroidPlatform, more recommendedParcelableSerialization, although writing is complex, but the cost is less, so for a more rapid data serialization and deserialization, system encapsulationBundleClass, convenient for us to carry out data transmission.
  • Intents use binders to transmit data between bundles. Binder buffers are limited in size (approximately 2M, depending on the model). A process has 16 binder threads by default, So the buffer size for a single thread is smaller (about 128 KB for a single thread), Pass data will happen to The Binder transaction failed because it was too large TransactionTooLargeException such anomalies.

  • Why can’t IntEnts pass objects directly between components rather than through serialization?

Intent when start the other components, will leave the current application process, enter the ActivityManagerService process (Intent. PrepareToLeaveProcess ()), it also means that, The data carried by an Intent must be able to be transferred between different processes. Android is based on Linux. Java objects cannot be transferred between different processes. Therefore, objects need to be serialized to transfer objects between application processes and ActivityManagerService processes. Either Parcel or Serializable can serialize objects. Serializable is easy to use but not as good as Parcel, which is an Android interface for things like interprocess communication