Android Question Global Variables issue

Nickelgrass

Active Member
Licensed User
Longtime User
Hello,
I am programming an app with several activity modules and one main activity. In the main activity in sub process_globals I have defined a few global variables that are used in all activities.
When I start the main activity and from there some of the other activities all is fine.
But sometimes I need to start a sub activity directly. The problem is that the global variable is then empty.
How can I work around that?

Second question is about layout colors. I have two color themes for the app. What is the best way of saving and loading the colors? Now I have the global variables where I save the color in for all the activities and a code module with sub to load the different colors to the variables. Any advice for how to do this efficiently?

Thanks!
Regards
 

ac9ts

Active Member
Licensed User
Longtime User
In the sub activity, have an error check that will set the global to a default value if empty.
 
Upvote 0

Nickelgrass

Active Member
Licensed User
Longtime User
Thanks for the reply. Thats the problem, it is not allowed to be a default value but needs to be the specific value.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Hi Nickelgrass,
if I understand it correctly, you have some process vars that got their init values only when your app starts from Main but are left "undetermined" when a service wakes up your app from a different seconday activity.
Why don't you simply use the same solution you indicated for point two (layout colors)?
I mean, a specific sub in a module, able to load proper values in those process global vars. Then you call that sub from each activity start function (even from main, for that matter).
This way, any activity has the opportunity to load values in those vars, even values specific for that only activity, if this applies.

udg
 
Upvote 0

Nickelgrass

Active Member
Licensed User
Longtime User
Ok, thanks for the reply. I was not sure that was the best way to do it. I suppose I will try it like that.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Ok, fine.
BTW, if the loaded values are supposed to be the same for any activity, you may want to deploy a "semaphore" var in process globals so to indicate whether the vars were already loaded or not. This should buy you some efficiency, especially if you have a lot of values to load and the source of those values is of slow access.
 
Upvote 0
Top