I am implementing an application using a timer.
In the timer, I call a method to get an image from a server.
Inside the timer, I also print the value of variable i, and increment it.
After that I try to print i‘s value using logcat.
But sometimes it prints like this:
1 2 3 4 5 5 6 7 7 7 7 7 8 9 10 11 12 12 12 14
Why is this happening?
Timer tasks are all run on the same thread and are executed sequentially. OTOH it seems that your code is sometimes executed in parallel. This could only happen if your code creates a separate thread (possibly with AsyncTask, Handler, etc..).
So, do you use any code that creates a separate thread?