I'm trying to put a timer that begins at 0 on my app, and counts from 0 (seconds) changing from (1... 13... 59... 1:19, etc), and then ends pauses, or stops when the game ends. I want to be able to display this paused time to show how long it took for the user to finish playing.
I've tried the chronometer method(?) but it kept crashing the app and didn't work. Currently am trying to use thread t = new thread... but not having any luck.
1 of my tries
Thread t = new Thread(){@Override
public void run(){
try{
while(!isInterrupted()){
Thread.sleep(1000);
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView textViewTime = findViewById(R.id.textTimer);
long time = System.currentTimeMillis();
textViewTime.setText(time);
}
});
}
} catch (InterruptedException e) {
}
}
};
t.start();
Currently have 'time' underlined saying cannot resolve method setText(long) I've shamelessly tried created this counter re-using code from a different project but for that project I was used a SimpleDateFormat method so it was slightly easier.