Regarding Process_Global variables

Inman

Well-Known Member
Licensed User
Longtime User
I have a project with about 7 activities. The project has some system-wide variables needed so I declared them in the Process_Global of Main activity. Now I can access them from any activity with main.variablename. And this works too.

Now the issue is suppose the user is doing something on say the 6th activity. Now this activity accesses 2 global variables in it's Activity_Create using main.variable1 and main.variable2. Imagine the user gets a phone call while he is in 6th activity. He takes the call, talks for 30 minutes. Now when he hangs up, he automatically gets back directly to the 6th activity of my project.

Here is the issue. When he gets back, the 6th activity gets created again. Now when the process global variable is called with main.variable1, it returns a NullPointer error as if the variable is not declared at all. This may be because the Main activity is not created when the user gets back; he goes back to 6th activity directly.

How can we fix this? Can this be solved if all the Process_Global variables are declared in a separate Code module?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Sub Process_Globals of all modules run first when the process starts (the order between the modules is not defined).

You can use a code module with an Initialize sub. In this sub it will initialize the required process globals of itself or of other modules. Use a flag to make sure that this initialization only runs once.
 
Upvote 0
Top