Android Question What is Activity Process_Globals for

JMW

Member
Licensed User
Longtime User
As I understand it,
Public (process_global) variables should be declared and set / initialized in Service_Create of the Starter service

So what would you use Process_global in an activity for?
 

JMW

Member
Licensed User
Longtime User
Yes, that was the thread that started my question. That thread, which led to https://www.b4x.com/android/forum/threads/starter-service-consistent-single-entry-point.57599/ and then to Erel's tips - https://www.b4x.com/android/forum/threads/b4x-tips-for-b4x-developers.62121/
where he says

Public (process_global) variables should be declared and set / initialized in Service_Create of the Starter service.
So again, what is the process_global in an activity used for if all process_globals are declared and set in the starter service?
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
You don't have to use the Starter Service, it's optional, in fact, you can even remove it (if you read the post it's even mentioned there).

In short, using Process_Globals on ANY activity will make all variables declared there accessible to all activities.
 
Last edited:
Upvote 0

JMW

Member
Licensed User
Longtime User
I think I'm not making my question clear somehow. I understand what you are saying. Process_Globals are accessible by all activities. That's kinda my point. It seems then, that if I follow best practice which is to use the Starter service for Process_Globals, then Activity Process_Globals has no purpose?
Joan
 
Upvote 0

JMW

Member
Licensed User
Longtime User
Confused. If something declared in an activity process global is available to other activities, doesn't that mean they are public?
Sorry to be so dense, but something's not clicking for me here.
Joan
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Confused. If something declared in an activity process global is available to other activities, doesn't that mean they are public?
1) you might declare an activity variable in its Process_Globals as Private
2) in the Starter, declare and initialize variables that will be used by many modules
3) in the Activity Process_Globas declare variable that you will use as they were properties of the Activity, "parameters" of the Activity
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
I also use the Starter module to declare the variables that I want to save/retrieve (SaveSettings() and GetSettings()) even if they are only used in a single module or activity (not necessarily Starter).
That way, I have a single set of SaveSettings() and GetSettings() routines in the starter module and it saves everything for all activities (I call it before leaving any activity).

It may not be the best way or the only way but I have found it generally easier for me to manage that way.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I also use the Starter module to declare the variables that I want to save/retrieve (SaveSettings() and GetSettings()) even if they are only used in a single module or activity (not necessarily Starter).
That way, I have a single set of SaveSettings() and GetSettings() routines in the starter module and it saves everything for all activities (I call it before leaving any activity).

It may not be the best way or the only way but I have found it generally easier for me to manage that way.
If the data is strictly related to an Activity, you should read-write them in Activity_Resume and Activity_Pause (or, better, call the routine to read-write from these event routines), so that you can "more" easily reuse that Activity in other projects.
 
Upvote 0

JMW

Member
Licensed User
Longtime User
Getting closer...If it is private to the Activity, doesn't it belong in the Activity Globals?
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
Activity Globals exist only if the Activity exist.
if your turn your device from landscape to portrait, the activity is closed and recreated.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
Longtime User
If the data is strictly related to an Activity, you should read-write them in Activity_Resume and Activity_Pause (or, better, call the routine to read-write from these event routines), so that you can "more" easily reuse that Activity in other projects.

That's a good point. Since I use maps to save/retrieve settings, a single map file can be easily shared across all the activities. Thanks
 
Upvote 0
Top