Thread Sleep Is Inconsistance In Android
Solution 1:
Can i trust on Thread.sleep()?
You can trust it to behave as specified. But the specification says that a sleep will cause the thread to stop for at least that number of milliseconds. Under some circumstances, it could stop for longer. For example, if there is a lot of work for a higher priority thread to do, a lower priority thread may not be woken from the sleep for a long time.
Solution 2:
You can try:
LockSupport.parkNanos(nanos)
Or other methods it provides. It's more accurate.
Solution 3:
I found out that when you turn off the screen using power button then android go to sleep after sometimes. CPU also go to sleep when screen is off. That's whey Thread.sleep() is giving large delay. In my case my device was in sleep mode for 7.30
minute and when i turn on the screen cpu
wake up and start the Thread again. By acquiring the Partial_wake_lock you can hold cpu
to go to sleep even when you press the power button(not shutdown).
Post a Comment for "Thread Sleep Is Inconsistance In Android"