Android Tutorial [B4X] Features that Erel recommends to avoid

Many things have changed in B4X and also in the underlying platforms. I will try to list here all kinds of (old) features that have better alternatives.
B4X is backward compatible so these features still work. The recommendations are more relevant for new projects or when implementing new features.
  1. (B4A) ListView -> xCustomListView:
    ListView is difficult to work with and cannot be customized. It is also not cross platform.

  2. (B4i) TableView -> xCustomListView:
    Same as above.

  3. CustomListView module -> xCustomListView library:
    Using the module will break other libraries.

  4. Sub JobDone -> Wait For (j) JobDone:
    [B4X] OkHttpUtils2 with Wait For

  5. Sub Smtp_MessageSent (and others) -> Wait For ...:
    https://www.b4x.com/android/forum/threads/b4x-net-library-ftp-smtp-pop-with-wait-for.84821/#content

  6. DoEvents / Msgbox -> DoEvents deprecated and async dialogs (msgbox)

  7. All kinds of custom dialogs -> B4XDialogs: B4XDialogs are cross platform and are fully customizable:
    [B4X] Share your B4XDialog + templates theming code

  8. File.DirDefaultExternal -> RuntimePermissions.GetSafeDirDefaultExternal
    Truth is that you shouldn't use both of them and use XUI.DefaultFolder instead.
    https://www.b4x.com/android/forum/threads/67689/#content

  9. File.DirRootExternal -> ContentChooser / SaveAs
    https://www.b4x.com/android/forum/threads/132731/#content

  10. File.DirInternal / DirCache / DirLibrary / DirTemp / DirData / DirDefaultExternal / GetSafeDirDefaultExternal -> XUI.DefaultFolder

  11. Round2 -> NumberFormat, B4XFormatter:
    Most usages of Round2 are to format numbers. Modifying the number is not the correct way.

  12. TextReader / TextWriter with network streams -> AsyncStreams:
    Trying to implement network communication on the main thread will always result in bad results.

  13. TextReader / TextWriter -> File.ReadString / ReadList:
    Two exceptions - non-UTF8 files or huge files (more relevant to B4J).

  14. Activities -> B4XPages:
    This is a big change and it is the most important one. It is hard to explain how much simpler things are with B4XPages. The more complex the project the more important it is to use B4XPages. This is also true when building non-cross platform projects. [B4X] [B4XPages] What exactly does it solve?

  15. Platform specific API -> Cross platform API:
    This is of course relevant when there is a cross platform API. Some developers have a misconception that the cross platform features have drawbacks compared to the platform specific API.
    • Node / Pane / Button / ... -> B4XView
    • Canvas -> B4XCanvas
    • All kinds of platform specific custom views -> cross platform custom views (such as XUI Views).
    • EditText / TextField / TextArea / TextView -> B4XFloatTextField
    • fx (and others) -> XUI
    • MsgboxAsync / Msgbox2Async / (B4i) Msgbox -> XUI.MsgboxAsync / XUI.Msgbox2Async
  16. CallSubDelayed to signal a completion of a resumable sub -> As ResumableSub:
    [B4X] Resumable subs that return values (ResumableSub)

  17. CallSubDelayed / CallSubPlus to do something a bit later -> Sleep(x):
    There are many other useful usages for CallSubDelayed.

  18. Multiple layout variants -> anchors + designer script:
    When Android was first released there were very few screen sizes. This is no longer the case. You should build flexible layouts that fill any screen size. It is easier to do with anchors + designer script. It is difficult to maintain multiple variants.

  19. Building the layout programmatically -> using the designer when possible:
    If you are only developing with B4A then building the layout programmatically is a mistake but not a huge one.
    B4J and B4i handle screen resizes differently and it is much more difficult to handle the changes programmatically (there is video tutorial about it).
    Most custom views can only be added with the designer (there are workarounds that allow adding them programmatically).
    It is very simple to copy and paste designer layouts between different platforms and projects.

  20. Multiline strings with concatenation -> smart strings:
    [B4X] Smart String Literal

  21. (SQL) Cursor -> ResultSet:
    ResultSet is cross platform and is also a bit simpler to use.

  22. ExecQuery (non-parameterized queries) -> ExecQuery2:
    Making non-parameterized queries is really unacceptable. See point #5 for more information: https://www.b4x.com/android/forum/t...ommon-mistakes-and-other-tips.116651/#content
    It is also true for ExecNonQuery.

  23. ExecQuerySingleResult when it is possible that there are no results -> ExecQuery2
    This is a historic design mistake. Nulls and Strings don't go together. If there is a possibility that ExecQuerySingleResult will return no results (=Null) then don't use it and use ExecQuery2 instead.

  24. Downloading / making http requests with any other library or source other than OkHttpUtils2 (=iHttpUtils2) -> OkHttpUtils2
    OkHttpUtils2 is very powerful and can be extended in many ways, without modifying the source. It is also very simple to use.

  25. Shared modules folder -> referenced modules
    The shared modules feature was useful in the early days of B4X. With the introduction of referenced modules, there is no good reason to use it. Referenced modules cover the same use cases and more.

  26. VideoView -> ExoPlayer
    ExoPlayer is much more powerful and more customizable.

  27. StartServiceAt / StartServiceAtExact -> StartReceiverAt / Exact
    With a few exceptions, it is no longer possible to start services in the background.
Related thread: [B4X] "Code Smells" - common mistakes and other tips
More to come.
 
Last edited:

MrKim

Well-Known Member
Licensed User
Longtime User
I am hoping, for those of us with a bad memory, that these tips will be gradually added to the context help as has been done on some items (Doevents comes immediately to mind). So if I pick Listview it would just say Better To Use xCustomListView.

@Erel , thanks again for your astounding work.
 

Richard Phipps

Member
Licensed User
As I don't code for a job and intermittently do projects it's very difficult understanding changes and being able to be aware of changes. When searching for "how to do something" in tutorials the messages are often out of date and date back several years with lots of forum chatter with new threads pointing here and there and sometimes those are out of date.

Does anyone remember the old loose leaf type book where as changes occurred a page was replaced?

Would it not be possible to have something similar like w3 schools where everything up-to-date is listed with simple examples step by step how to. Effectively a BOOK subject by subject moving from the basics of coding to advanced topics but still offering the novice a chance of achieving their goal. Sometimes tutorials are written well here. Other times they seem to be written for experts assuming prior knowledge meaning someone like me can't pick up the thread as I have missing knowledge. An example of this is connecting to a remote server.

Just some ideas 😀
 

MiguelL

Member
Licensed User
Thanks for the list, however wouldn't it be better if for example on each point you put across you also include the alternative to use.

For example on this line,
  • (B4A) ListView -> xCustomListView: ListView is difficult to work with and cannot be customized. It is also not cross platform.
I don't seem to pick the recommended alternative.

Thanks.

I was thinking the exact same thing, but I think the alternative is what follows after "->".
 
As I don't code for a job and intermittently do projects it's very difficult understanding changes and being able to be aware of changes. When searching for "how to do something" in tutorials the messages are often out of date and date back several years with lots of forum chatter with new threads pointing here and there and sometimes those are out of date.

Does anyone remember the old loose leaf type book where as changes occurred a page was replaced?

Would it not be possible to have something similar like w3 schools where everything up-to-date is listed with simple examples step by step how to. Effectively a BOOK subject by subject moving from the basics of coding to advanced topics but still offering the novice a chance of achieving their goal. Sometimes tutorials are written well here. Other times they seem to be written for experts assuming prior knowledge meaning someone like me can't pick up the thread as I have missing knowledge. An example of this is connecting to a remote server.

Just some ideas 😀
I agree with Richard.

I have being using B4X for about two months now and have come to the conclusion it is both the best and worst development system that used (and I've used plenty over the years).
It's the best because of the potential for what can be developed, the IDE (especially the visual designer ) and you can see the sheer amount of effort that's gone into its development. But it's definitely the worst in terms of trying to learn it. Not from being able to follow what's written or spoken but from a point of knowing what's current functionality and how to use it. I've read the guides, followed tutorials, watched videos and spent endless hours trawling through the threads. Often to the point of forgetting what I started looking for.
I just don't think that a forum is the best place for the main source of what functionality exists and how to use it. Sure, its good for providing extra help and clarification (which may mean that the main documentation needs to be revised) and getting help with problems but not as the reference point.

Having said all that, I still persevere with it because I believe it is a good system and I'll get there in the end.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
I just don't think that a forum is the best place for the main source of what functionality exists and how to use it. Sure, its good for providing extra help and clarification (which may mean that the main documentation needs to be revised) and getting help with problems but not as the reference point.
1. As written above, you should start with the booklets: https://www.b4x.com/android/documentation.html
2. These comments have nothing to do with this specific thread. Posting comments not relevant to the thread topic are a guaranteed way to make it more difficult for others to find what they are looking for.

Any post not related to this thread topic will be deleted. You are all welcome to start a new thread for anything else.
 

Magma

Expert
Licensed User
Longtime User
Well a little "comment" i need to say...

There are some small and some big changes made to B4X - every day I am finding new ways or edit old ways because some changes making faster the code and "blah blah"....
The main reason I think that B4X Team (Erel) trying to keep compatibility with "old ways" (for example: b4xviews with nodes/panels) but also trying to create a (one) language for 3 platforms [android/java(Desktop:Windows-Linux-MAC)/iOS]... that sometimes kill the programmer... From the other hand a programmer is not human is an audit-machine :)

I think that if someone start now using B4X it is easier...

but if someone was already started must follow the new rules and re-learn some (at least the differents).... no need if don't want because there is the compatibility for old way... but if need to be fast or having the new goodies... must read again and again...
 

ilan

Expert
Licensed User
Longtime User
TableView -> xCustomlistview ?

can you create a table in xClv? like scrolling horizontal and vertical? any example available?
thanx
 

b4x-de

Active Member
Licensed User
Longtime User
Could you please explain in more detail what is wrong on using a ListView? ListView seems to me as a simple solution for simple requirements. Why don't use therefore?

I also found Erel deleted the Text of the former ListView Tutorial. But I was wondering why.

I'm also wondering whether it is good idea to delete knowledge from the forum at all.

Thomas
 

toby

Well-Known Member
Licensed User
Longtime User
Could you please explain in more detail what is wrong on using a ListView? ListView seems to me as a simple solution for simple requirements. Why don't use therefore?
Listview vs xCustomListview is analogous to Abacus vs a calculator.

It's NOT recommended anymore for most people to use an abacus for calculation, even though you still can use it if you really want to.
 

DonManfred

Expert
Licensed User
Longtime User
Top