Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 有没有办法安排计时器在特定日期开始?_Java_Android - Fatal编程技术网

Java 有没有办法安排计时器在特定日期开始?

Java 有没有办法安排计时器在特定日期开始?,java,android,Java,Android,我想让倒计时计时器在将来到达时的特定时间启动 这是我现在写的代码。我需要一种时间监听器,它能在时间到的时候启动计时器。该应用程序通常是关于投标开始时间和结束时间 CountDownTimer c = new CountDownTimer(tender.getTime(), 1000) { public void onTick(long millisUntilFinished) { long days = TimeUnit.MILLISEC

我想让倒计时计时器在将来到达时的特定时间启动

这是我现在写的代码。我需要一种时间监听器,它能在时间到的时候启动计时器。该应用程序通常是关于投标开始时间和结束时间

     CountDownTimer c = new CountDownTimer(tender.getTime(), 1000) {

        public void onTick(long millisUntilFinished) {



            long days = TimeUnit.MILLISECONDS.toDays(millisUntilFinished);
            millisUntilFinished -= TimeUnit.DAYS.toMillis(days);

            long hours = TimeUnit.MILLISECONDS.toHours(millisUntilFinished);
            millisUntilFinished -= TimeUnit.HOURS.toMillis(hours);

            long minutes = TimeUnit.MILLISECONDS.toMinutes(millisUntilFinished);
            millisUntilFinished -= TimeUnit.MINUTES.toMillis(minutes);

            long seconds = TimeUnit.MILLISECONDS.toSeconds(millisUntilFinished);


            if (days == 0) {
                if (hours == 0) {
                    time.setText(minutes + ":" + seconds);
                } else {
                    time.setText(hours + ":" + minutes + ":" + seconds);
                }
            } else if (hours == 0) {
                time.setText(minutes + ":" + seconds);
            } else {
                time.setText(days + " days , " + hours + ":" + minutes + ":" + seconds);
            }



        }

        public void onFinish() {
            time.setText("over");
        }

    };


    if(tender.calcTimer(tender.getStartTender(),tender.getStartTime())>=0){
        time.setText("didn't start yet");
    }
    else if(tender.getTime()<=0){
        time.setText("over");
    }
    if (time.getText().toString().equals(null)) {

        c.start();

    }
CountDownTimer c=new CountDownTimer(tender.getTime(),1000){
公共void onTick(长毫秒未完成){
长天数=时间单位。毫秒。今天(毫秒到完成);
毫秒直至完成-=时间单位。天。托米(天);
长时间=时间单位。毫秒。到小时(毫秒到完成);
毫秒直至完成-=时间单位。小时。托米(小时);
长分钟=时间单位毫秒到分钟(毫秒到完成);
毫秒直至完成-=时间单位。分钟。托米(分钟);
长秒=时间单位毫秒到秒(毫秒到完成);
如果(天数==0){
如果(小时==0){
time.setText(分钟+“:”+秒);
}否则{
time.setText(小时+“:“+分钟+”:“+秒);
}
}否则,如果(小时==0){
time.setText(分钟+“:”+秒);
}否则{
time.setText(天+“天”,“小时+”:“+分钟+”:“+秒);
}
}
公共无效onFinish(){
time.setText(“结束”);
}
};
if(tender.calcTimer(tender.getStartTender(),tender.getStartTime())>=0){
time.setText(“尚未启动”);
}

否则,如果(tender.getTime()Use alarm managerJobScheduler API更好,很可能与位于可扩展列表适配器中的新This timer相同,我不知道如何从alarm manager调用它。