I have a service that is set to start at boot and runs every hour.
When the service finishes I issue a StartServiceAt("",NextRunTime,True) and then Service.StopForeground(1). I understand the service will start itself at the next specified run time even though it is no longer in the Foreground.
But my service depends on some Main.Process_Globals. So if within that hour the phone needed some resources and killed my Main (or I cold booted the phone), my Main.Process_Globals are uninitialized.
Specifically I have an HttpClient which needs to be initialized only once and I do so in Main. HttpClient does not seem to have an .isinitialized, so I can't tell if it is initialized later on or not.
I could lose my variables either by not running my service in the foreground, or by cold booting.
So, is it OK to re-initialize my httpclient each hour in the service just in case? I thought I read that this was not a good idea. I certainly do not want to keep my service in foreground, that seems bad form. Even worse, when starting from a cold boot, HTTPClient is not initialized at all.
Please let me know the best way to handle this.
Thanks!
When the service finishes I issue a StartServiceAt("",NextRunTime,True) and then Service.StopForeground(1). I understand the service will start itself at the next specified run time even though it is no longer in the Foreground.
But my service depends on some Main.Process_Globals. So if within that hour the phone needed some resources and killed my Main (or I cold booted the phone), my Main.Process_Globals are uninitialized.
Specifically I have an HttpClient which needs to be initialized only once and I do so in Main. HttpClient does not seem to have an .isinitialized, so I can't tell if it is initialized later on or not.
I could lose my variables either by not running my service in the foreground, or by cold booting.
So, is it OK to re-initialize my httpclient each hour in the service just in case? I thought I read that this was not a good idea. I certainly do not want to keep my service in foreground, that seems bad form. Even worse, when starting from a cold boot, HTTPClient is not initialized at all.
Please let me know the best way to handle this.
Thanks!