B4X Booklets
B4XPages
Cross-platform projects
Copyright: © 2022 Anywhere Software Edition 2.4
Last update: 2022.08.15
Table of content 2 B4X Cross-platform projects
1 B4X platforms .............................................................................................................................. 4
2 First steps ..................................................................................................................................... 5
2.1 AdditionalLibraries folder structure ..................................................................................... 6
3 B4XPages ..................................................................................................................................... 8
3.1 What exactly does it solve? .................................................................................................. 8
3.2 What is a B4XPage?............................................................................................................. 9
3.3 New cross-platform B4XPages project .............................................................................. 10
3.4 B4XPages project structure ................................................................................................ 13
3.5 Code templates ................................................................................................................... 14
3.6 B4XMainPage Code template ............................................................................................ 15
3.6.1 B4XPage events ............................................................................................................. 16
3.6.1.1 B4XPage_CloseRequest ........................................................................................ 17
3.6.2 B4XPage methods .......................................................................................................... 18
3.6.3 Launch the IDE of another platform .............................................................................. 19
3.6.4 Generate a zip file for the project ................................................................................... 19
4 Compatibilities B4A B4i B4J XUI ........................................................................................ 20
5 Copy layouts, move views ......................................................................................................... 21
5.1 Copy layouts ...................................................................................................................... 21
5.2 Move views between pages ................................................................................................ 22
6 Access objects from another Page.............................................................................................. 23
7 B4X Templates........................................................................................................................... 24
8 Project with 2 pages B4XPagesTwoPages ................................................................................. 27
8.1 Steps to follow ................................................................................................................... 28
8.2 Setup of a project ............................................................................................................... 30
8.3 Modify the Package name in Build Configurations ........................................................... 31
8.4 Add a new B4XPage to the project .................................................................................... 31
8.4.1 Code of B4XMainPage .................................................................................................. 33
8.4.2 Code of B4XPage1 ......................................................................................................... 35
8.5 Create a B4XPages project zip file .................................................................................... 37
9 B4XPages version of the SecondProgram project ..................................................................... 38
9.1 Project structure ................................................................................................................. 38
9.2 B4J code adaptation ........................................................................................................... 41
9.3 B4A adaptation................................................................................................................... 43
9.4 B4i adaptation .................................................................................................................... 43
9.5 Conclusion ......................................................................................................................... 43
10 B4XPages Navigation through pages and program flow ........................................................... 44
11 B4XPagesNavBar ...................................................................................................................... 45
12 Other projects in the forum ........................................................................................................ 47
Table of content 3 B4X Cross-platform projects
Main contributors: Klaus Christl (klaus), Erel Uziel (Erel)
To search for a given word or sentence use the Search function in the Edit menu.
All the source code and files needed (layouts, images etc.) of the example projects in this guide are
included in the B4XPagesSourceCode folder.
You can download all the source codes from the forum on this link:
https://www.b4x.com/android/forum/threads/b4x-documentation-booklets.88985/#content
Updated for following versions:
B4A version 11.80
B4i version 8.00
B4J version 9.80
B4X Booklets:
B4X Getting Started
B4X Language
B4X IDE Integrated Development Environment
B4X Visual Designer
B4X Help tools
B4XPages Cross-platform projects
B4X CustomViews
B4X Graphics
B4X XUI B4X User Interface
B4X SQLite Database
B4X JavaObject NativeObject
B4R Example Projects
1 B4X platforms 4 B4X Cross-platform projects
1 B4X platforms
B4X is a suite of programming languages for different platforms.
B4X suite supports more platforms than any other tool
ANDROID | IOS | WINDOWS | MAC | LINUX | ARDUINO | RASPBERRY PI | ESP8266 | AND
MORE...
B4A Android
B4A is a 100% free development tool for Android applications, it includes all the features
needed to quickly develop any type of Android app.
B4i iOS
B4i is a development tool for native iOS applications.
B4i follows the same concepts as B4A, allowing you to reuse most of the code and build
apps for both Android and iOS.
B4J Java / Windows / Mac / Linux / Raspberry PI
B4J is a 100% free development tool for desktop, server and IoT solutions.
With B4J you can easily create desktop applications (UI), console programs (non-UI) and
server solutions.
The compiled apps can run on Windows, Mac, Linux and ARM boards (such as Raspberry
Pi).
B4R Arduino / ESP8266
B4R is a 100% free development tool for native Arduino and ESP8266 programs.
B4R follows the same concepts of the other B4X tools, providing a simple and powerful
development tool.
B4R, B4A, B4J and B4i together make the best development solution for the Internet of
Things (IoT).
B4XPages
B4XPages is an internal library for B4A, B4i and B4J allowing to develop easily cross-
platform programs.
B4XPages is explained in detail in the B4XPages Cross-platform projects booklet.
Even, if you want to develop only in one platform it is interesting to use the B4XPages
library it makes the program flow simpler especially for B4A.
2 First steps 5 B4X Cross-platform projects
2 First steps
This guide shows the best practices for developing cross-platform projects for B4A, B4i and B4J
with the goal to use as much as possible the same code.
What does cross-platform project mean?
The main goal is to have most of the code the same for all three platforms.
To develop cross-platform projects, some simple ‘rules’ should be followed.
1. Use the B4XPages cross-platform framework to manage pages.
2. Use as much as possible B4XViews, included in the standard XUI library.
These are oversets of the platform specific standard views.
3. Use as much as possible views from the XUI Views library.
These are cross-platform custom views.
4. Use as much as possible XUI CustomViews.
5. When you add a common module:
a. Copy it to the parent folder if it is a new module for the project.
b. Link it with a relative path if it is already in the parent folder.
c. Or link it with an absolute path for modules valid for other projects.
d. Do not copy it to the project folder, or only if it is specific to the platform.
That way, when you modify a common module and save it, the code in the other
IDEs is automatically updated.
You should decide directly at the beginning which platforms you want use.
Even for single platform projects it is useful to follow the simple rules above. Because the
B4XViews have some properties not exposed directly in the corresponding platform and are cross-
platform.
For development, I prefer to start with B4J, because no device needed for testing, and then adapt for
the other platforms.