The Runnable
interface is another way in which you can implement multi-threading other than extending the Thread
class due to the fact that Java allows you to extend only one class.
You can however, use the new Thread(Runnable runnable) constructor, something like this:
private Thread thread = new Thread(new Runnable() {
public void run() {
final long start = mStartTime;
long millis = SystemClock.uptimeMillis() - start;
int seconds = (int) (millis / 1000);
int minutes = seconds / 60;
seconds = seconds % 60;
if (seconds < 10) {
mTimeLabel.setText("" + minutes + ":0" + seconds);
} else {
mTimeLabel.setText("" + minutes + ":" + seconds);
}
mHandler.postAtTime(this,
start + (((minutes * 60) + seconds + 1) * 1000));
}
});
thread.start();