Android Code Snippet A more elegant way to detect platform

I have been using #if B4A for several years. Then yesterday I looked at the source code for B4XPageManager, and there @Erel sometimes uses xui.isB4A.
I wanted to allow for the slower speed of Android device so I used xui.isB4A for the first time. I like it. Thank you @Erel.

B4X:
     If xui.IsB4A Then Sleep(5500) Else Sleep(4500)

Note there is also xui.isB4J and xui.isB4i.
 

Cableguy

Expert
Licensed User
Longtime User
I have been using #if B4A for several years. Then yesterday I looked at the source code for B4XPageManager, and there @Erel sometimes uses xui.isB4A.
I wanted to allow for the slower speed of Android device so I used xui.isB4A for the first time. I like it. Thank you @Erel.

B4X:
     If xui.IsB4A Then Sleep(5500) Else Sleep(4500)

Note there is also xui.isB4J and xui.isB4i.
Keep in mind that #if B4... is not there to determine wich platform the code is running on but rather to allow code to behave differently (even with different syntax) according to the platform. This can be code inside a sub or even a complete set of different subs targeting different platforms.
The xui.isB4... is just another boolean that allows you to make code decisions YOURSELF.

In addition... the code tagged inside a #if B4... is ignored by the compiler according to wich IDE you are compiling it in.
Using xui.isB4.. as your only means of determining platform may produce errors at compile time.
 
Top