Within the application, the best way to transfer custom objects between actions?

I know that this question has been asked several times, and I went through many of these questions ... almost all of these questions make you use a great interface for your class. However, in a few questions, I came across a quote:

"NOTE: viewing Parcelable may ask why Android doesn’t use the built-in Java serialization engine? It turns out that the Android team concluded that serialization in Java is too slow to satisfy the Interrocess-communication Androids requirements. Thus, the team built a Parcelable solution. For the approach Parcelable requires that you explicitly serialize members of your class, but in the end, you get much faster serialization of your objects.Also understand that Android provides two mechanisms that allow you to transfer data to another The first is to transfer the beam to the action using the intent, and the second is to transfer the Opportunity for service.The two mechanisms are not interchangeable and should not be embarrassed. That is, Parcelable is not intended to convey activity. If you want to start an activity and give him some data, use the kit. Parcelable is intended to be used only as part of the AIDL definition. "

This quote can also be found in the Pro Android 2 book.

Now, seeing that all actions in one application are performed in the same process ( Each activity in Android is a process or one application is a single process ), unless otherwise specified in the manifest, the connection within the action of the same applications is not interprocess communication per se. Is it really faster to use the parcelable class, or is it enough to pass the attributes of an object through a package through an intent?

Shedding light on this aspect will be greatly appreciated. Greetings!

+2
source share
3 answers

Here is the FAQ . :)

: Android : ; ; HashMap of WeakReferences to Objects ( ). , , - , . (, , , .)

+8

Parcelable : , Bundle, , , , . , : Bundle, HashMap put/get .

AIDL IPC ( ) , : Parcelable . remote, Parcelable.

+5

docs:

Parcelables

Parcelable ( ) . writeParcelable (Parcelable, int) readParcelable (ClassLoader) writeParcelableArray (T [], int) readParcelableArray (ClassLoader) . , , , , .

, Parcelables: writeTypedArray (T [], int), writeTypedList (List), readTypedArray (T [], Parcelable.Creator) readTypedList (List, Parcelable.Creator). : , Parcelable.Creator . ( Parseable , Parcelable.writeToParcel Parcelable.Creator.createFromParcel.)

A special container of type "Bundle" is available for a map of keys / values ​​of heterogeneous values. It has many optimizations to improve read and write performance and the type-protecting API avoids complex debugging errors when finally sorting the contents of the data into a parcel. Ways to use writeBundle (Bundle), readBundle () and readBundle (ClassLoader).

+1
source

Source: https://habr.com/ru/post/1768660/


All Articles