More efficient approach for Android stopwatch code?
<p>I'm a newbie to Android app development, so I know I'm probably making things way too complicated.</p>

<p>The code below works as expected (after many hours!!!), but I'm curious whether I'm handling the implementation of the two threads correctly? Like I said it runs at least, but I'm not sure if it's all necessary.</p>

<p>PS: Bonus points for showing me the formula to convert centiseconds into h:m:s:c so that I don't have to use that horrible String length solution I found lol! [EDIT ... see below, I found the answer to this part]</p>

<pre><code>package com.test.advancedtimer;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Timer;
import java.util.TimerTask;

public class MainActivity extends AppCompatActivity {
    String time;   //Clock's combined time
    String elapsedTime;    //Stopwatch elapsed time
    int stopwatchHour = 0;
    int stopwatchMin = 0;
    int stopwatchSec = 0;
    int stopwatchCentiSec = 0;
    int elapsedSeconds = 0;
    int elapsedCentiseconds = 0;    //cumulative Centiseconds elapsed since starting countdown

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        updateTime();

    }

    //First timer that updates the clock display once every second
    public void updateTime() {
        Timer clockTimer = new Timer();
        clockTimer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                getTime();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        TextView timeTextView = (TextView) findViewById(R.id.time_display);
                        timeTextView.setText(getTime());
                    }
                });
            }
        }, 0, 1000);
    }

    //Accesses system time and concatenates it into 'time' String, then returns it.
    public String getTime() {
        Calendar cal = new GregorianCalendar();
        int hour = cal.get(Calendar.HOUR);
        int min = cal.get(Calendar.MINUTE);
        int sec = cal.get(Calendar.SECOND);
        int AM_PM = cal.get(Calendar.AM_PM);
        String AMorPM = "";

        // Establishes two-digit format for clock time
        time = (hour &lt; 10 ? "0" : "") + hour + ":";
        time += (min &lt; 10 ? "0" : "") + min + ":";
        time += (sec &lt; 10 ? "0" : "") + sec;

        if (AM_PM == 0) {
            AMorPM = "AM";
        } else if (AM_PM == 1) {
            AMorPM = "PM";
        }

        time += " " + AMorPM;
        return time;
    }

// Second timer that triggers the stopwatch to increment by centiseconds (1/10th seconds)
    public void startTimer(View view) {
        Timer stopwatchTimer = new Timer();
        stopwatchTimer.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        TextView timerTextView = (TextView) findViewById(R.id.runningTimer);
                        timerTextView.setText(stopwatch());
                    }
                });

            }
        }, 0, 10);
    }

    // Returns the combined string for the stopwatch, counting in tenths of seconds.
    public String stopwatch() {

        elapsedSeconds = elapsedCentiseconds / 100; //Conversion to enable use of same formula above
        stopwatchHour = elapsedSeconds / 3600;
        stopwatchMin = (elapsedSeconds % 3600) / 60;
        stopwatchSec = elapsedSeconds % 60;

        //Formats stopwatch to two digits per time unit.
        elapsedTime = (stopwatchHour &lt; 10 ? "0" : "") + stopwatchHour + ":";
        elapsedTime += (stopwatchMin &lt; 10 ? "0" : "") + stopwatchMin + ":";
        elapsedTime += (stopwatchSec &lt; 10 ? "0" : "") + stopwatchSec + ":";

        //Grabs last two digits of total centiseconds for centisecond component.
      String centiSeconds = String.valueOf(elapsedCentiseconds);
        if (centiSeconds.length() &gt;1) {
            elapsedTime += centiSeconds.charAt(centiSeconds.length() - 2);
            elapsedTime += centiSeconds.charAt(centiSeconds.length() - 1);
        } else {
            elapsedTime += "0" + centiSeconds.charAt(centiSeconds.length() - 1);
        }

        elapsedCentiseconds++;
        return elapsedTime;
    }
}
</code></pre>

<p><strong>EDIT: I finally got the maths to work for the conversion from deciseconds (which I switched to because the 100th of seconds digit was moving too fast to be of any use):</strong></p>

<pre><code>// Returns the combined string for the stopwatch, counting in tenths of seconds.
    public String stopwatch() {

        //elapsedSeconds = elapsedDeciseconds / 10; //Conversion to enable use of same formula above
        stopwatchHour = (elapsedDeciseconds % 2160000) / 36000;
        stopwatchMin = (elapsedDeciseconds % 36000) / 600;
        stopwatchSec = (elapsedDeciseconds % 600) / 10;
        stopwatchDeciseconds = elapsedDeciseconds % 10;

        //Formats stopwatch to two digits per time unit.
        elapsedTime = (stopwatchHour &lt; 10 ? "0" : "") + stopwatchHour + ":";
        elapsedTime += (stopwatchMin &lt; 10 ? "0" : "") + stopwatchMin + ":";
        elapsedTime += (stopwatchSec &lt; 10 ? "0" : "") + stopwatchSec + ":";
        elapsedTime += stopwatchDeciseconds;

        elapsedDeciseconds++;
        return elapsedTime;
    }
</code></pre>