Android Tutorial B4XObject - B4A /B4J / B4i objects serialization

upload_2014-12-16_17-0-36.png
upload_2014-12-16_17-1-8.png


The RandomAccessFile libraries (B4A, B4J and B4i libs) include two new methods: WriteB4XObject and ReadB4XObject.

These methods are similar to WriteObject and ReadObject. The main difference is that WriteObject / ReadObject methods are based on Java serialization feature. This means that they are not compatible with iOS.

The new B4XObject methods use a custom serialization method and is therefore supported by all platforms.

They are also faster than WriteObject / ReadObject.

The following types are supported by WriteB4XObject:
Lists, Maps, String, primitives, user defined types and arrays. Only arrays of bytes and arrays of objects are supported (in B4A and B4J).
Including combinations of these types (a list that holds maps for example).

Note that if you plan to share types between different platforms then the types should be declared in the main module.

The signatures of WriteB4XObject / ReadB4XObject are similar to WriteObject / ReadObject with one difference. There is no Compress parameter (compression is always used).

The updated AsyncStreamsObject modules are available here: https://www.b4x.com/android/forum/threads/asyncstreamsobject-module.48276/#post-300097

Edit: For new projects it is recommended to use B4XSerializator. It is similar to the methods discussed above but it is simpler to use and more powerful.
 
Last edited:

manolitoGnet

Member
Licensed User
Longtime User
So, No way to store a type with a menber as Bitmap?

B4X:
Error occurred on line: 254 (Main)
Cannot serialize: <UIImage: 0x19086bc0>, {91, 91}
Stack Trace: (
  CoreFoundation       <redacted> + 150
  libobjc.A.dylib      objc_exception_throw + 38
  CoreFoundation       <redacted> + 0 

...
 

manolitoGnet

Member
Licensed User
Longtime User
Note that this is an old tutorial. It is better to use B4XSerializator.


Not directly. You will need to convert the bitmap to an array of bytes.

Ok, Erel thanks.

Will take a look to B4XSerializator and/or try to convert bitmap...
 
Top