Android Question Process globals and globals

AAA128

New Member
Licensed User
Longtime User
Hey people I'm new to b4a I have been trying things out however I am bit confused on process global and global I've tried to make use of the expiation provided in the package as well as the treads however I am still so confused on what they are if it is possible would anyone be able to provide me with some expiations with examples? if anyone could help me please I would be grateful
 

barx

Well-Known Member
Licensed User
Longtime User
Globals and Process Globals are used to provide scope. Here are some scenarios:

If a variable is declared in one of your sub procedures it will only be available to use within that code block.

If a variable is declared in Globals then you can access it within the entire code mode.

If a variable is declared in Process Globals then you can access it anywhere in the project. If you are accessing in the same module as it is declared the you do so as normal. If you want to access it from another module you prefix the module name. Example, a variable called Username declared in then Main activity Process Globals would be accessed with Main.Username.

Hope this helps
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
Besides scope, persistence is a factor: a Process Global hangs around as long as your app; a Global may be created and destroyed, for example when the device is rotated.

So, for instance, if you have an app where a user signs in to a web service, and you want to maintain that connection all the time, you might put all the information about the user (their name, user id, perhaps an access token) in Process Globals, so that even if the device is rotated, you still have that data, and can go back to the web service, or whatever you're doing, without having to prompt them for credentials again.

In the Globals, you might store information that helps you work out the display - for instance, calculations that work out the size of images, or how many you can fit across the screen, because those do need to be done differently for each orientation.

Some types of data can, frankly, be initialised anywhere, and it won't matter. But others might have a considerable penalty in setting them up - in time or other resources. For example, if you were building a list of all the files on a device, or fetching a chunk of data from the internet, then store it in a Process Global, otherwise you'll have to rebuild it each time the user rotates their device, which would affect performance. Users will be ok with a pause on first startup; they're unlikely to want to sit through each just because the screen rotated.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Good shout @nwhitfield, forgot to mention persistence.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…