Issue
I am using the SystemClock.elapsedRealtime()
to display the time.
But now I want to show the seconds one-by-one to be increase based on the SystemClock.elapsedRealtime()
time.
And yes I must use the thred.
So how to do it ?
I have tried it with this thread:
// Start lengthy operation in a background thread
progressThread = new Thread(new Runnable() {
public void run() {
while (mProgressStatus < 1000) {
mProgressStatus = ((int) (SystemClock.elapsedRealtime() / 10));
// Update the progress bar
mHandler.post(new Runnable() {
public void run() {
// try {
// // progressThread.sleep(1000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// progressBar.setProgress(mProgressStatus);
System.out.println("SECOND is :" + mProgressStatus);
}
});
}
}
});
So what should I change in this thread to get seconds one by one to be increased ??
Please help me for this.
Thanks.
Solution
You can use the Chronometer class. You can bind it to SystemClock.elapsedRealtime()
using setBase()
. Another way could be if you use Handler inside an Activity and using the sendEmptyMessageDelayed() method with value 1000 to update your timer.
Answered By - hovanessyan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.