Android 安卓暂停计时器

Android 安卓暂停计时器,android,timer,Android,Timer,嗨,这是我的代码: public class Match extends Activity{ TextView timervalue; long timeInMilliseconds = 0L; long timeSwapBuff = 0L; long updatedTime = 0L; String secondHalf; private long startTime = 0L; private Handler customHandler

嗨,这是我的代码:

public class Match extends Activity{
    TextView timervalue;
    long timeInMilliseconds = 0L;
    long timeSwapBuff = 0L;
    long updatedTime = 0L;
    String secondHalf;
    private long startTime = 0L;
    private Handler customHandler = new Handler();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.match);

        secondHalf = null;
        Button startButton;
        Button l;
        timervalue = (TextView) findViewById(R.id.timerValue);
        startButton = (Button) findViewById(R.id.startButton);
        l = (Button) findViewById(R.id.button1);
        l.setOnClickListener(new View.OnClickListener() {



            public void onClick(View view) {

                timeSwapBuff += timeInMilliseconds;
                customHandler.removeCallbacks(firstHalf);
            }

        });
        startButton.setOnClickListener(new View.OnClickListener() {



            public void onClick(View view) {

                startTime = SystemClock.uptimeMillis();
                customHandler.postDelayed(firstHalf, 0);
            }

        });

}


    private Runnable firstHalf = new Runnable() {
        public void run() {
            timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
            updatedTime = timeSwapBuff + timeInMilliseconds;

            int secs = (int) (updatedTime / 1000);
        //    int mins = secs / 60;

            secs = secs % 91;

            int milliseconds = (int) (updatedTime % 1000);

       //    timervalue.setText("" + mins + ":"
            timervalue.setText("" + "minuto" + ":"
                    + String.format("%02d", secs)); //+ ":"

                 //   + String.format("%03d", milliseconds));

            customHandler.postDelayed(this, 0);
            if ( secs == 10 ) {
                secondHalf = "X";
                timeSwapBuff += timeInMilliseconds;
                customHandler.removeCallbacks(firstHalf);  
            }
        }





    };



}
为什么我能够停止计时器并继续单击按钮,而在等待10秒(如代码中所示)并单击按钮后不能恢复计时器?什么变化

这不起作用:计时器停止,但没有继续的理由

             if ( secs == 10 ) {
            secondHalf = "X";
            timeSwapBuff += timeInMilliseconds;
            customHandler.removeCallbacks(firstHalf);  
        }

你们到底想发生什么?你们考虑过改用Timer类吗?当Timer到达10时,Timer正确地继续暂停,但在我再次按下按钮cor continue后也显示10