从某个时间继续实时计数

时间:2015-05-05 19:19:34

标签: java android timer real-time

我的应用程序会算一段时间。开始时间将存储在数据库中。我希望应用程序能够在某个时间进行实时计数,这将是用户启动应用程序的时间。

private void countTime(String inDate){
    onStartControll = true;
    long inDateInt = Long.parseLong(inDate);
    long dateNow = Long.parseLong(String.format("%02d",date.getTime()));
    long timeCounted = dateNow - inDateInt;

    startTime = timeCounted;
    timeInMilliseconds = timeCounted;
    customHandler.postDelayed(updateTimerThread, 0);
}

private Runnable updateTimerThread = new Runnable() {
    public void run() {
        if(onStartControll == false) {
            timeInMilliseconds = SystemClock.uptimeMillis() - startTime;
        } 

        updatedTime = timeSwapBuff + timeInMilliseconds;
        int secs = (int) (updatedTime / 1000);
        int mins = (int) (secs / 60);
        int minsShown = secs / 60 % 60;
        int hours = (int) (mins / 60);
        secs = secs % 60;

        int milliseconds = (int) (updatedTime % 100);
        timerValue.setText(String.format("%02d", hours) + ":" + String.format("%02d", minsShown) + ":"
                 + String.format("%02d", secs));
        customHandler.postDelayed(this, 0);
    }
};

问题是当我启动它时计时器不会继续计数。

0 个答案:

没有答案