Android Tutorial [B4X] [B4XPages] What exactly does it solve?

Status
Not open for further replies.

Erel

Administrator
Staff member
Licensed User
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:
  1. Provide a cross platform layer.
  2. Make it simple to develop B4A apps.
The advantages of the cross platform layer are clear. B4XPages hides many of the differences between B4A activities, B4i pages and B4J forms. With B4XPages it is trivial to create a multiple "pages" app where all of the code is shared (except of the template code which is just pasted to the main module).
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:
  1. 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.
  2. 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.
  3. The page classes are never destroyed separately. The class global variables and views state will never be reset (until the process is killed).
The 3 points above make many things simple. Some of them are:
  1. Events are never missed or queued.
  2. Sleep calls are never cancelled. For example, no longer do we need to restart animations in Activity_Resume.
  3. The UI state is kept as long as the process lives.
  4. In most cases we don't need to use the starter service.
  5. We can directly call public methods of other pages. No need to use CallSub or CallSubDelayed.
  6. We can directly access public global variables of other pages.
  7. We can directly access and manipulate views of other pages.
  8. We can decide whether to create the layouts immediately when a page is created (B4XPages.AddPageAndCreate).
  9. We can move views between pages.
  10. No need to worry from cases where CallSubDelayed starts the previous activity unexpectedly (usually happens with HttpJobs).
  11. We can use the same page class to create many page instances.
  12. A single place with a single and simple behavior for the global variables.
  13. No need to think what should be initialized when FirstTime = True and what needs to be initialized every time.
  14. No need to handle cases where a different activity, other than Main, is started first.
  15. Better control over the pages stack as it is implemented in B4X code.
  16. Automatic handling of the up indicator. No need to use AppCompat library for this.
  17. Very simple and flexible way to handle the back key.
  18. 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).
  19. No distinguish between classes with "activity context" which must be declared in Globals to other classes that can be declared in Process_Global.
  20. No need to split the implementation between a stateless UI layer and a stateful non-UI layer.

As B4XPages is still very new, there aren't many examples. 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:

Sandman

Well-Known Member
Licensed User
When you feel B4XPages have matured enough, it might be a good idea to make a B4X video tutorial about it. Perhaps even two: One focused on the cross-platform aspect, and one on how much it simplifies B4A projects (perhaps by making a simple project old-school, and then showing how to do the same thing using B4XPages). I know I would very much appreciate both of these videos.
 

Patrick Clark

Member
Licensed User
This is excellent, it will solve all of the headaches I have had with Activities.

BUT... a couple of questions

1. how do you turn off the animation when a page is shown. I have tried reducing the animation Duration in the designer but this doesn't have any effect.

2. how do you get the page object required for many operations. "Me" is used for the current page but how do you reference a different page. eg I want to set page3 title
B4X:
B4XPages.SetTitle(xxx, "Title")
how do i get "xxx"
 
Last edited:

Jack Cole

Active Member
Licensed User
This is great and will remove a lot of the headaches of Android development and cross-platform development. B4X is getting to be hard to beat for cross-platform apps!

Do you have any plans for adding the ability to support changing orientations? Maybe just doing it like b4i with the page_resize event?
 

Erel

Administrator
Staff member
Licensed User
1. how do you turn off the animation when a page is shown. I have tried reducing the animation Duration in the designer but this doesn't have any effect.

2. how do you get the page object required for many operations. "Me" is used for the current page but how do you reference a different page. eg I want to set page3 title
It is really better to post these questions in a new thread.
1. Add this line to B4XMainPage:
B4X:
B4XPages.GetManager.TransitionAnimationDuration = 0
2. There are all kinds of ways to do it. Two examples:
B4X:
B4XPages.SetTitle(B4XPages.MainPage.Page2, "Title")
Or use GetPage:
B4X:
B4XPages.SetTitle(B4XPages.GetPage("page 2"), "Title")
When you feel B4XPages have matured enough, it might be a good idea to make a B4X video tutorial about it
Agreed.

Do you have any plans for adding the ability to support changing orientations? Maybe just doing it like b4i with the page_resize event?
See this discussion: https://www.b4x.com/android/forum/t...ed-orientation-limitation.118939/#post-744020
 

abilio486software

Member
Licensed User
Hi,

Seems to be an excelente solution for abstracting the Activity lifecycle, but I have some doubts about large projects and complex projects and interfaces.

- We will be working under the same and only Activity ?
- If so, we still can use inline java for that Activity?
- It is possible to avoid the designer and build the visual interface by code, using Addview?

Thanks
 

Martin Larsen

Active Member
Licensed User
This sounds very, very cool!

A few questions:
  • Are B4XPages meant mostly for beginners or are they for all levels?
  • You mention certain limitations, but only detail the orientation change. What other limitations are there?
  • Are there any penalties when it comes to performance etc?
Edit: I have played with some of the examples and changed them a bit etc. You are right, it is almost insanely simple! And best of all, much more of the code is shared between B4A and B4i.
 
Last edited:

Erel

Administrator
Staff member
Licensed User
1. Not at all. It is for all levels.
2. As B4XPages is still very new it is possible that we will discover more limitations. For now the single orientation in B4A is the only one that I'm aware of.
3. No. On the contrary, as everything in B4XPages is simple it is also simpler to better manage the views and remove unneeded views if necessary (which is not likely to happen in 95%+ of the apps).
 

Peter Simpson

Expert
Licensed User
Here's another working example but using live data from the net. Page 1 continues loading images (in the background) when page 2 is showing browser information (in the foreground).


When I get a chance, I'll upload my continuous counter example.
 

sorex

Expert
Licensed User
Erel,

I couldn't get the pm init to work by copy pasting the declaration line from the other tutorial (I can't post there)
and it seems that there is a typo in the (other) tutorial after making some minor changes to the lib.

is has dim pm as B4XPageManager instead of B4XPagesManager there in the first code part of post 1.


The usage of this (extra) B4XMainPage is a little odd. in most cases this is the menu so I prefer to call my menu class menu.
I can add it but then it's an extra class that doesn't do much besides being a requirement.
Maybe adding an initialize2 method in the future where we can set the default page/class instead? (pm.initialize2(activity,menu))

Edit: I'll think about the above again when I'm through my process. It might be ideal for long booting apps to have it as splash screen.
 
Last edited:

luke2012

Well-Known Member
Licensed User
Hi @Erel thank you for this useful post.
About B4XPages I have a couple of questions (before start a new customer project):
1) Can you tell when it became in a final version (actually is in beta) ?
2) The B4XPages is compatible with [B4X] OkHttpUtils2 ?

Thanks in advance for your reply :)
Luca.
 
Status
Not open for further replies.
Top