In my case , I use std::this_thread::sleep_for(10ms) to sleep 10ms.
If the Android app is in foreground, will sleep about 10ms. But if app in background ,it will sleep about 50ms~.
I also tried usleep(),nanosleep(),std::condition::wait_for(), and also java Thread.sleep(), NONE of them works fine in this case.
But this code works fine always:
int64_t startTimeStemp = now_ms();
while(true) {
int64_t nowTimeStemp = now_ms();
if(now - start > 10) {
break;
}
}
How can I solve this problem? Thanks.