as the starter service will never killed as long as your app is running so is the best point for initializes or hold resources(Global resources)In Erel's recent "tips for B4X developers" post (which motivated me to clean up my code), he states that "Public (process_global) variables should be declared and set / initialized in Service_Create of the Starter service".
I understand that it's best to initialize/assign values to those public variables in Starter > Service_Create, because it's the only guaranteed entry point.
However, does it really matter where we declare our Process_Global variables - in Starter, or a common code module, or an activity?
There are a few reasons I ask this:
- I typically put PG variables in a common code module called "c", so the prefix is kept short when referenced from other modules (e.g. c.someVariable instead of Starter.someVariable). It reduces clutter a bit.
- If a PG variable is mostly used in a single module (and rarely referenced outside it), I usually put the variable in that module to keep it "close to home" (and to avoid prefixing in most cases).
- I'm hoping to minimize the amount of code I need to move around, probably because I'm lazy.
That's basically my question right there - if I declare my image in a code module, and initialize it in the Starter>Service_Create, is that OK?imagine you have a service which started by ServiceStartAt at background and uses an sql object or an image which is declared and initialized in Code Module. now can your service get access to that sql object or image if your app is closed!!!?
@klaus: i always thought the order should be the below, since the starter service is the initial entry point of any application that has it:Main.Process_Globals
That's correct (they will also be "fine" even if the service is no longer active).Am I correct in assuming that Process_Globals declared in code modules would therefore be treated the same as if they were declared in the starter process, and would be fine as long as the service is active?
Hello,Under what conditions, besides stopping the service in code, would the service stop running?
In fact it is a "service" so you should or shouldn't stop it depending on what you need to be done. It's your choice.Should we kill the starter service in the activity_pause event?