Service destroy?

ScarBelly

Member
Licensed User
Longtime User
I have a newbie question.
I have a custom service (pollStatusService) that calls HttpUtils every 20 seconds. The log looks like this:
Starting Job: pollStatus
** Service (httlutilsservice) Create **
** Service (httlutilsservice) Start**
** Service (httlutilsservice) Destroy **
** Service (pollstatusservice) Start**
Starting Job: pollStatus
** Service (httlutilsservice) Create **
** Service (httlutilsservice) Start**
** Service (httlutilsservice) Destroy **
** Service (pollstatusservice) Start**
....

Should I create and destroy my service each time or should I avoid creations and destructions?
I don't know which is best for memory management but I did run this for 16 hours continuous without issues and only used half the battery life. Normally, it will run for 9 hours.
 

wl

Well-Known Member
Licensed User
Longtime User
I tried something similar but with a 'startserviceat' (every 30 seconds) and had the impression it drained my battery quite fast


Wim
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
When a service has nothing to do, it will get destroyed, until it is scheduled again, and then it starts again.
That is their lifecycle. I dont think there is anything you can do to avoid it.
And it is definitely better power-wise, memory-wise and processing-wise to let it be destroyed and free resources.

EDIT:
Btw...why are you polling so frequently? Doing HTTP requests every 30/20 seconds does not seem correct to me.
 
Upvote 0

ScarBelly

Member
Licensed User
Longtime User
Thanks for the responses.

I'm polling frequently because this is a strictly in-house, wi-fi, production line monitoring app where timely alerts are critical. Battery drain isn't bad since there is no 3g and most messages are very short. I have just had it up and running in test mode for 5 days. The device is not to be used for general purpose though there may be a couple of more small apps.

It will run on battery power for around 23 hours and I ran it over the weekend (4:00pm Friday - 7:00am Monday) charging. I logged the polls on the server side and missed 33 polls at 20 second intervals and never missed two in a row. When network traffic went down over Monday morning there were no misses.

My question remains. Should I actively destroy the service after each poll?
 
Upvote 0

wl

Well-Known Member
Licensed User
Longtime User
Yes, I would have the service end after each poll and restart the service in the indicated interval with "startserviceat"
 
Upvote 0
Top