I am trying to create an app which sends sms. As confirmation I requires user to hold down a "Send" button for one second. I am showing a progress bar which acts like countdown timer for them. I wanted to update progress of progress bar every 10 miliseconds and increment it by 1. By this approach I would get 100% progress in exactly 1 second. But I was not able to be that accurate. I have tried, runnables and countdown timers but everything failed.
Right now I am using this "hack" which uses time difference in milis to calculate progress add:
progressBar = (ProgressBar) findViewById(R.id.progressBarSend);
handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
if(progressStatus <= 100) {
progressStatus += (int)((System.currentTimeMillis() - currentTime)/10f);
currentTime = System.currentTimeMillis();
progressBar.setProgress(progressStatus);
handler.postDelayed(this, 10);
}else{
handler.removeCallbacks(this);
}
}
};
By this approach I have got +- 200ms accuracy on emulator. Is there any better way to be even more accurate?
Thanks in forward