0

I have an app that writes some data to a file every second. I used a Timer that and schedule it at a fixed interval of 1000 for the most part it works fine, but sometimes i notice there are seconds, or sometime even minutes where there is no data in the log file.

Is there any likely suspects to this problem?

Pita
  • 1,444
  • 1
  • 19
  • 29
  • 2
    Please post some code so we can take a look at what you've done so far. – Tyler Jan 29 '14 at 02:57
  • If I am not mistaken, Timer will automatically tick every 1000 milliseconds or 1 sec. Please post some code along with logcat output. – Rohan Kandwal Jan 29 '14 at 03:05
  • are you using a thread? like a game-loop? if you are you should just use deltaTime instead of the timer function – Green_qaue Jan 29 '14 at 03:23

1 Answers1

0

Timer runs in background thread(s) that are not reliable. From the docs:

Each timer has one thread on which tasks are executed sequentially. When this thread is busy running a task, runnable tasks may be subject to delays.

LINK: http://developer.android.com/reference/java/util/Timer.html

If you have a time sensitive task, then you need to check SystemClock like here:

How to measure elapsed time

Community
  • 1
  • 1
Jim
  • 10,172
  • 1
  • 27
  • 36