Android Question Timer in a service module

InfiniteImp

Member
Licensed User
Longtime User
Hi,

I'm working on an app which needs to regularly monitor a network share for files. I have a service module checking every 15 seconds using a timer. The problem is that it works well for a while but after some period of time (maybe an hour? not sure) the timer starts behaving unpredictably. Sometimes it fires once a minute, sometimes once every 3 minutes, sometimes 5 or more. The interval changes even though I am not setting the interval to 1, 3 or 5 minutes.

I just read in the documentation that "Timer events will not fire when the activity is paused, or if a blocking dialog (like Msgbox) is visible.". Well, my activity is paused because the interface is not visible - I generally leave it sitting at the home screen. Maybe I'm misunderstanding the documentation as I'm still new to this.

I'm counting on the timer to be running regardless of the UI. Is this the wrong way to do it? If not, how can I get an event to fire at regular intervals?

Thanks.
 

InfiniteImp

Member
Licensed User
Longtime User
Thanks for the suggestion. I may have gotten this to work (I made some changes on when timers run, as I have 3 of them) as well as disabling a timer prior to changing its interval, then enabling it. I left it running overnight and this morning it still performed its timer check correctly. However, if after more testing this does not work out then I'll do what you suggested and use StartServiceAt.

Appreciate the suggestion.
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
I forgot to mention. Now I use "Wait For" in the download service. So even though service takes too long a new service is only scheduled after completion.
 
Upvote 0
Top