Android Code Snippet Thread usage

This is a new forum category for the benefit of us all. It is intended as a place to share code snippets that you feel may be of interest to other developers. It could be a couple of lines, or a class.

We want to make this as easy to access as possible to which end Erel has agreed to implement parsing a Tag: line and boosting Forum search results based on it's content.

This is B4a only for now, although any code that is not UI related should work on B4j, provided any required libraries are available. If it takes off, we may get a B4j forum too.

You can see the thought process behind this forum in the thread here.

In order that the samples are as easy to find as possible, the following is the suggested content:


Description: A brief outline of the purpose of the snippet

Code (in code block)

Dependencies: A list of additional libraries that the code needs to work.

Tags: <list of keywords>

It is intended that the Tag line is also used in postings in the general forums if the poster feels that the code may be useful to more than just the person that asked the question, this should make them easier to find. The onus to do this is on the poster, it will benefit everybody if we can remember to do it. If I forget, please feel free to nudge me in the appropriate thread to add tags.

If you find a piece of code that is in an old thread that you feel is worthy being made available, then that too can be posted in this forum. In which case please include the following in the post.
Original Poster: i.e. @stevel05 The original poster would then be notified of it's inclusion.

A link to the thread for context.

Please check that the code has not already been added

This is an experiment for all of us, please feel free to contribute code or comments.

If I've missed and information from this post, please let me know.
Last edited:


B4X founder
Staff member
Licensed User
Longtime User
Small tip: If you copy syntax highlighted code from one post to another the spaces are removed due to a bug in the forum editor (at least on Firefox).

You can fix it by pressing on the wrench icon:

Now the editor will be in "plain" mode and will not break the code format.