I write a simple AsyncTask which:
@Override
protected Void doInBackground(Void... params) {
for (int i = 0; i <= 99; i++) {
long time = System.currentTimeMillis();
try {
//Wait for 6ms
Thread.sleep(6);
} catch (InterruptedException e) {
e.printStackTrace();
}
long diff = System.currentTimeMillis() - time;
Log.d(TAG, "Row "i + " is DONE with timeDiff=" + diff + "ms vs. waitTime=" + waitTime + "ms");
publishProgress(i);
}
}
It works well in some of test devices until I try on LG devices (Nexus 4, G3): time to sleep seems longer than I think. After checking log, I see in normal case, timeDiff is 6ms or 7ms; while with LG devices, timeDiff is mostly > 40ms.
Also try to use SystemClock.sleep()
but no luck.
Could anyone please suggest me how to fix it? Any help would be appreciated!