We are developing Android apps using Java.I set the conditional branch using localtime and isafter so that the timer starts at a specific time, but the countdown does not work at the specified time.What should I do?
package com.example.countdowntimer;
import androidx.announcement.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Build;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.widget.TextView;
import java.text.ParseException;
import java.time.LocalDateTime;
public class MainActivity extensions AppCompatActivity{
@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@RequiresApi(api=Build.VERSION_CODES.O)
public void compareDate1()throws ParseException {
LocalDateTimedate1 = LocalDateTime.parse("2020-02-7T10:48:00.000");
LocalDateTimedate3 = LocalDateTime.now();
if(date1.isAfter(date3)){
CountDownTimer countDownTimer = new CountDownTimer (3600000, 1000) {
@ Override
public void onTick (long millisUntilFinished) {
int time=(int)millisUntilFinished/1000;
int time2 = (int) millisUntilFinished/60000;
int time3 = (int) millisUntilFinished/3600000;
(((TextView) findViewById(R.id.tv)) .setText("+time3+":"+time2+":"+time%60);
}
@ Override
public void onFinish(){
((TextView) findViewById(R.id.tv)) .setText("Finish";
}
}.start();
}
}
}
CompareDate1 is not called anywhere.
Are they meant to be embedded somewhere in the Activity lifecycle?
© 2024 OneMinuteCode. All rights reserved.