B4XPages makes many things simple and even trivial.
As Android developers, we are dealing with these challenges for many years now so it might take us a while to understand how simple things can be.
As explained in B4XPages tutorial, there are two purposes for B4XPages:
With activities, it requires creating an activity + shared class + page / form module for each page. A lot of work.
Even if you are only interested in B4A development, B4XPages can help you a lot. I will list here all kinds of challenges that become simple with B4XPages.
The three most important things regarding the B4XPage classes are:
You can see how the Bluetooth chat example became much simpler
Old: https://www.b4x.com/android/forum/threads/android-bluetooth-bluetoothadmin-tutorial.14768/#content
New: https://www.b4x.com/android/forum/threads/b4xpages-bluetooth-chat-example.119014/#content
With that said, no one is forced to switch to B4XPages. Everything will continue to work exactly as before. It is too soon to rush and convert large working projects.
B4XPages also has some limitations, especially regarding to the locked orientation (in B4A only) and it is still in a preliminary version.
As Android developers, we are dealing with these challenges for many years now so it might take us a while to understand how simple things can be.
As explained in B4XPages tutorial, there are two purposes for B4XPages:
- Provide a cross platform layer.
- Make it simple to develop B4A apps.
With activities, it requires creating an activity + shared class + page / form module for each page. A lot of work.
Even if you are only interested in B4A development, B4XPages can help you a lot. I will list here all kinds of challenges that become simple with B4XPages.
The three most important things regarding the B4XPage classes are:
- The page classes are 100% regular classes. They don't have a special life cycle and you can do whatever you like with them. There are some B4XPages events but they don't affect the state of the class itself. This is not the case with activity modules.
- The page classes are never paused. Nothing special happens when a page is no longer visible or when the app moves to the background. Eventually of course, the whole process will be killed when the app is in the background.
- The page classes are never destroyed separately. The class global variables and views state will never be reset (until the process is killed).
- Events are never missed or queued.
- Sleep calls are never cancelled. For example, no longer do we need to restart animations in Activity_Resume.
- The UI state is kept as long as the process lives.
- In most cases we don't need to use the starter service.
- We can directly call public methods of other pages. No need to use CallSub or CallSubDelayed.
- We can directly access public global variables of other pages.
- We can directly access and manipulate views of other pages.
- We can decide whether to create the layouts immediately when a page is created (B4XPages.AddPageAndCreate).
- We can move views between pages.
- No need to worry from cases where CallSubDelayed starts the previous activity unexpectedly (usually happens with HttpJobs).
- We can use the same page class to create many page instances.
- A single place with a single and simple behavior for the global variables.
- No need to think what should be initialized when FirstTime = True and what needs to be initialized every time.
- No need to handle cases where a different activity, other than Main, is started first.
- Better control over the pages stack as it is implemented in B4X code.
- Automatic handling of the up indicator. No need to use AppCompat library for this.
- Very simple and flexible way to handle the back key.
- Background / Foreground events that are raised in all pages when the app moves to the background and to the foreground (not so simple to get with activities and required in many cases).
- No distinguish between classes with "activity context" which must be declared in Globals to other classes that can be declared in Process_Global.
- No need to split the implementation between a stateless UI layer and a stateful non-UI layer.
You can see how the Bluetooth chat example became much simpler
Old: https://www.b4x.com/android/forum/threads/android-bluetooth-bluetoothadmin-tutorial.14768/#content
New: https://www.b4x.com/android/forum/threads/b4xpages-bluetooth-chat-example.119014/#content
With that said, no one is forced to switch to B4XPages. Everything will continue to work exactly as before. It is too soon to rush and convert large working projects.
B4XPages also has some limitations, especially regarding to the locked orientation (in B4A only) and it is still in a preliminary version.
Last edited: