Android Question B4XSerializator and types declared outside main module

Dave O

Well-Known Member
Licensed User
Longtime User
B4XSerializator says that it wants any types to be defined in the Main module. Why is that?

Background:
I'm building a multi-user version of my checklist app using CloudKVS, which uses B4XSerializator to send objects back and forth.

Normally I declare my types and most global variables and constants in a code module called "c" (for "common", but shorter as a prefix in the code). That's also where I put subs that are used across activities, because it's a central place. That's worked well in all my apps so far.

But if I try to use those types with B4XSerializator, it fails because it expects to find them in Main.

So I guess this is more a question about best practices - doesn't it make more sense to declare app-wide stuff in a code module rather than in a particular activity? Do I really need to move all those types that CloudKVS needs into my Main module?

Just seems a bit counter-intuitive. Am I missing something?

Thanks!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Tip: you shouldn't have multiple activities. Switch to B4XPages.

You can have the custom types declared in any module, with the exception of types that will be deserialized on a different platform / app. Like in the case of CloudKVS. So all the custom types that are added to CloudKVS need to be declared in B4XMainPage or Main module.
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
B4XPages: My app is Android only (for now), and at the time B4XPages came out, it was too limited for my needs (orientation changes, etc.). I do plan to try it for my next app, but it's not feasible for my checklist app right now.

Thanks for your quick reply, but I do already know about the Main-module constraint. My question was, why impose that constraint? Why does B4XSerializator (and/or CloudKVS) care which module I declare my types in?

I'm assuming there's a good technical reason for this; I'm just asking because it seems odd to me (and will make for a lot of tedious code changes).

Thanks again.
 
Upvote 0

Dave O

Well-Known Member
Licensed User
Longtime User
Thanks, moving the participating types to the Main module fixed the error.

And the code change was easy - I didn't have to change/move any variables based on those types because the types themselves are accessible globally (without a module prefix).
 
Upvote 0
Top