If I understand correctly, the variables that are written in Process_Globals will be created when the Activity Module is created. How long can they exist?
For example, I have the main module Main and in it I created several Process_Globals variables. When will variables in a given module be destroyed? For example, how long can I not work with this module (where these variables were created) for the variables from it to continue to exist? What will happen to them if the phone is locked, but the application is not closed?
Not true I'm afraid. Variables declared in Sub Globals in an Activity are local to the Activity and are lost when the Activity is destroyed. Variables declared in Sub Process_Globals in an Activity belong, as the name implies, to the entire process and are only lost when the entire process is destroyed. See the comments about each Sub that are at the beginning of each Sub when a new project is generated.
More specifically, in the Main activity in Process Globals, I create a text variable. Then I work with this variable in other activity modules and periodically use this variable. I have a suspicion that at some point this variable is changed or destroyed, but when I can't catch that moment... I also use one class module. I often pass this variable to this module, perhaps it is somehow related and I need to pass a copy of this variable?
Not true I'm afraid. Variables declared in Sub Globals in an Activity are local to the Activity and are lost when the Activity is destroyed. Variables declared in Sub Process_Globals in an Activity belong, as the name implies, to the entire process and are only lost when the entire process is destroyed. See the comments about each Sub that are at the beginning of each Sub when a new project is generated.
More specifically, in the Main activity in Process Globals, I create a text variable. Then I work with this variable in other activity modules and periodically use this variable. I have a suspicion that at some point this variable is changed or destroyed, but when I can't catch that moment... I also use one class module. I often pass this variable to this module, perhaps it is somehow related and I need to pass a copy of this variable?
Process globals are declared as static variables of the class of the Activity. As such they are present even when no instances of the Activity class are instantiated and is why they are universally accessible. On the other hand normal global variables are declared as instance variables of the Activity class and are only available to the instance of that Activity class
Java:
public class main extends Activity implements B4AActivity{
public static double aprocessglobalvariable;
public double aglobalvariable
}
Process globals are declared as static variables of the class of the Activity. As such they are present even when no instances of the Activity class are instantiated and why they are univerally accessible. On the other hand normal global variables are declared as instance variables of the Activity class and are only available to the instance of that Activity class
Java:
public class main extends Activity implements B4AActivity{
public static double aprocessglobalvariable;
public double aglobalvariable
}
Bad thing (we talked about something similar in another thread).
A class itself does not exist if it is not instantiated (it is not a code module), so any public "part" of it (variables or methods that are) should not exist.
I don't like code modules. They are quite limited in B4A. They do have their place, especially with constants and other primitive variables, but if there are other good options then use them.
For a B4XPages, in most cases the best place for app-global variables is in Class_Globals of B4XMainPage.
It is easily accessible and the app starts from B4XMainPage.
The only(?) case where you can't use B4XMainPage is if your B4A app starts in the background. For example with a push notification. For that cases I recommend using the starter service (Process_Globals). If it is a cross platform project then using a code module will be better.
Again, for simple constants it doesn't really matter and code modules are perfect.
In any case, a class, an Activity, a B4XPages should be created for a specific purpose, functionality, not to provide public variables to be used by an entire project (unless, of course, their content does not strictly depend on that component itself)
A class itself does not exist if it is not instantiated (it is not a code module), so any public "part" of it (variables or methods that are) should not exist
Wrong - you obviously don't understand static class variables. They exist as part of the class definition that is used to make instances of that class and as the class definition (the class of the class) must exist to make instances of a class then by definition the static variables are always available.
1 - they cannot handle events
2 - (and this is not a real limitation of code modules) for some things (serialization) you shouldn't declare custom types there.
Wrong - you obviously don't understand static class variables. They exist as part of the class definition that is used to make instances of that class and as the class definition (the class of the class) must exist to make instances of a class then by definition the static variables are always available.