Android Question Sending lists between B4A and B4J issue

techknight

Well-Known Member
Licensed User
Longtime User
So, I have a list of a customtype in B4A, as well as the same customtype in B4J

The Custom type is this:

B4X:
Type MediaFile(FileName As String, FileType As String, Subdir As String, Duration As String, Thumbnail As String, Blob() As Byte)

Basically that customtype gets declared and inserted into a list called MediaFiles. This list is basically the filename, path and thumbnail as well as binary (if requested) of each file inside a directory on the PC.

the PC builds the list during startup, and if I request it via command.

This list builds, and works fine.

The issue occurs when I send this list over MQTT to B4A. It crashes.

So basically what I do is take the MediaFile list, and put it in a Map as the Value. The Key is "MediaFiles"

I send this map over MQTT using B4XSerializator.

The Map comes back from the topic over to B4A, it gets De-Serialized back into a Map, and then I select case with the Map's Key. Once I see if a key is "MediaFile", I then pass the object as a list into a CallSub.

This is when the crash occures.

First it crashed with this:

B4X:
java.lang.IllegalArgumentException: argument 1 should have type anywheresoftware.b4a.objects.collections.List, got java.util.ArrayList

But now, it keeps crashing with out of memory errors when it gets the object from B4J to B4A over MQTT.

I logged the MQTT response deserialized. Here it is:
B4X:
md.studiobb.main:_commanager_getmediafiles, [[[Blob=[B@43664d68, Duration= 00:00:07.06, FileName=logo720p.mp4, FileType=video/mp4, Thumbnail=iVBORw0KGgoAAAANSUhEUgAAAUAAAADwCAIAAAD+Tyo8AABKbklEQVR42u29d3RV9brvPftcZZbVkkBCCT2990boiAgqKiqiYgFRQZAqvfcQIITepEpRQNxiAQ (I cut off the rest for the sake of post sanity)

Then of course it truncates it in the log because its so long.

Any ideas? I am sure there is a better way to do this but this is the best way I knew how.

Basically the PC caches all the media files into a list, and grabs each and every one of their thumbnails and sends it to B4A so a user can "browse the media" remotely. When a person wants to watch a video as a preview, I request the binary blob of that 1 file and send it back. That's the theory anyway.
 

techknight

Well-Known Member
Licensed User
Longtime User
I switched MQTT communication over to Maps entirely, no lists. That seems to have solved my issue.

I just read the list at one end, and build the list at the other.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…