Android Question Is there any harm in using timer inside a service?

Juzer Hussain

Active Member
Licensed User
Longtime User
Hi Guys,
In my service i have used ServiceStartAt and set to recur after 5 secs(cannot increase more).But some times job inside service takes more than 5 secs to complete as such the service starts again(while the job is still running) and i get duplicate data.
Can i use timer to start service at fixed intervals.I will disable it before starting job and enable again after the job is over.

Pls advise.

Thanks
Juzer
 

Daniel-White

Active Member
Licensed User
Longtime User
I had a similar problem, one service in background take gps info each 2 minutes, when I run my APP with the service already in background , my APP execute again another ServiceStartAt and overlap the service in background. I don't know if this your issue?, I fix it with this in my MAIN activity, the service "THESERVICE" has inside the ServiceStartAt.

If IsPaused(THESERVICE)= True Then
StartService(THESERVICE) 'the service is not in RAM in background so time to start it.
Else
ToastMessageShow"THESERVICE is already running",True)
End If
 
Upvote 0

Juzer Hussain

Active Member
Licensed User
Longtime User
Thanks Daniel-White for quick answer,
We can use timer in service as pointed out by Erel (I could not see earlier) in one of the threads i guess in my case it is much more manageable.
Thanks
Juzer
 
Upvote 0
Top