Polling variables from a running service?

BlueVision

Active Member
Licensed User
Longtime User
Using in my app-code GPS, primary for counting the distance on the move in 1 second intervals to have a software mileage tracker and also for detecting locations, finally creating a protocol with a timestamp of the trip. All the code for that I put into the main program and that worked so far. So there is in the next step now the creation of a service module, doing all the GPS-stuff independent to prevent loosing information if my app goes to background and gets paused. (If a phonecall would reach me or whatever, my measuring stops.)

So the problem is now, I can start the service, but I am not able to poll the variables from the service directly from the main of my app (Servicename.Variablevalue) and to import its values to it for doing a reflecting refresh. In this way it does not work and it's slowly driving me nuts. I modified the variables in the service already with static values for testing, but these static values are not reaching my app too. Probabaly a problem interacting between service and my app.

So whats the best way to do it? Starting the service again and again with startserviceat in intervalls of 1 second is not the best idea I think. Better to keep the service somehow running in background and permanently collecting the data and doing calculation on it. So I am not really sure if it's enough to have a LocationChanged-Routine inside the service, which should fire new values when moving and the service is active. Or do I have to implement an additional timer for that? The thing is, that LocationChanged will eventually deliver data in shorter or longer intervals. For counting the amount of way this is not a good basis, so there is a need for a defined timedelay and then based on that timedelay ask for the actual values. I found a working way previously in the main app with a timer, but putting a timer inside a service is creating new problems.

Another way could be using callsubdelayed somehow. I have no idea about implementing it, found no example piece of code for it forcing me into the right direction. It could be the fact, that there are some timing issues run against my dogmatic 1-second-system, but this could be solved with timestamps for the data I get and doing some exact calculation with it.

If anybody of you would give me a hint how to poll values of variables from a running service, that would bring me out of that problem. Comments and help are really welcome.

BV
 
Top