Android Question Warning 24

Nickelgrass

Active Member
Licensed User
Longtime User
Hello,
I have a service that contains a status variable in Process_global. I access this variable from different activities and other services. I get the compiler warning 24 (Accessing fields from other modules in Sub Process_Globals can be dangerous as the initialization order is not deterministic. (warning #24)).
Why is that. How can I avoid it? Should I make a sub that returns the status instead?
Thanks
Regards
 

agraham

Expert
Licensed User
Longtime User
Each Sub Process_Globals is run in turn as the app is first started. However the order in which they run is not determined so if one Process_Globals accesses a Public field in the Process_Globals of another module that may happen before that Process_Globals has been run so the field may not yet be initialised. It sounds like this is what you are doing.

Remove any accesses to Public Process_Globals fields from any other Process_Globals and the warning should disappear.
 
Upvote 1
Top