Android Question best to declare private constants in process_globals or globals?

Dave O

Well-Known Member
Licensed User
Longtime User
If I have private (activity-specific) constants, should I declare them in:

Sub Globals - has the right scope, but are redeclared each time the activity is created
or
Sub Process_Globals - process scope can be overridden with Private keyword, and only declared once (more efficient?)

Background:
I have dozens (sometimes hundreds) of constants, mostly enumerations or shared strings, like this:
B4X:
Dim Const FILE_SUCCESS As Int = 1
Dim Const FILE_CORRUPT As Int = 2
Dim Const FILE_MISSING As Int = 3
Dim Const FILE_FORMAT_SKETCH As String = "png"
Dim Const FILE_FORMAT_HTML As String = "html"

Normally I would just follow the natural scope and make these activity constants (i.e. in Globals), but I started thinking that a large number of constants is inefficient to redeclare each time the activity is created. Then I thought "Meh, it's just integers and strings, no big stress to recreate them."

So, is there a best solution, or is it just a matter of style?

Thanks!
 

Dave O

Well-Known Member
Licensed User
Longtime User
Put in a Module. Dunno if this is the right way in B4X but in VB.NET it does!

Agreed, I do have a code module that has the app-wide constants (and variables and subs).

The ones I'm wondering about (above) are the constants specific to each activity. :)
 
Upvote 0

Derek Johnson

Active Member
Licensed User
Longtime User
Background:
I have dozens (sometimes hundreds) of constants, mostly enumerations or shared strings, like this:
B4X:
Dim Const FILE_SUCCESS As Int = 1
Dim Const FILE_CORRUPT As Int = 2
Dim Const FILE_MISSING As Int = 3
Dim Const FILE_FORMAT_SKETCH As String = "png"
Dim Const FILE_FORMAT_HTML As String = "html"
!

I suggest that you create a code module per activity with a meaningful name. Then put the declarations in that module.

Then you will be able to use the Intellisense feature to pick your constants by typing 'modulename.' . You will then get a drop down with all of the constants listed.
 
Upvote 0
Top