Android Question include a common piece of code

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
hi

i have 2 apps
in both i use a piece of code that generates dynamic data required by both
currently i use the same code in both so for each modification i need to copy and paste the code into both overwriting the existing code
is there a way i can have an external file with the b4a code or even just a text code so then i can parse it to avoid copy & paste?
what i mean is that i want to modify that text file and on runtime to use the content as the data
i did try using a file on the server and download it but i think this way should be better
is it?
the online & download file has one big advantage as i can modify it without recompile and redistribute
any views / opinions / suggestions?

thanks
 

DonManfred

Expert
Licensed User
Longtime User
- You can NOT load B4A-Code at runtime. B4A-Code is compiled to java at COMPILEtime.
- The code can not be compiled to java at runtime.

Use a class to implement this functionality and add this class to both your apps. You have to update both app for sure when the class changed.
 
Last edited:
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Thanks
That's exactly what i do now
So i need to recompile on every chane both apps
I think the text file with updated data on the server to be downloaded and parsed will be the best as i will be able to update the date dynamically without recompile and re distribute
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Not sure I understand what you are trying to do.
If both app wants to use a common class or module, you can create a b4x library and both projects load the same library.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
Not sure I understand what you are trying to do.
If both app wants to use a common class or module, you can create a b4x library and both projects load the same library.
Either library / class / module is what i do now so on every change i need to recompile and distribute again
I wanted tondo it dynamically
So i change the code in a text file that the app will download and use
This way no need to recompile and distribute on every change

Seems it's impossible so I'll stick to the current approach

Thank you all
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
You could look at URLClassLoader if you want to load a class at runtime. Be aware this a security problem though, and would require quite a bit of 'new' code in your app to work.
 
Upvote 0

Zeev Goldstein

Well-Known Member
Licensed User
Longtime User
guys,
thank you all for your good will
i will keep on using the same way i do now as i anyhow have to update the app in the store from time to time as google demands sdk targeting etc so the existing way is the only solution for me
once again thank you all
 
Upvote 0
Top