我想发送用户AbcActivity到XyzActivity后,倒计时计时器是finished.like这个我在AbcActivity上设置了5分钟的倒计时计时器,当倒计时计时器将是0或完成时,它会自动发送用户AbcActivity到XyzActivity。
我该怎么做呢?
`
txtDay = (TextView) findViewById(R.id.txtDay);
txtHour = (TextView) findViewById(R.id.txtHour);
txtMinute = (TextView) findViewById(R.id.txtMinute);
txtSecond = (TextView) findViewById(R.id.txtSecond);
tvEventStart = (TextView) findViewById(R.id.tveventStart);
mButton= (Button) findViewById(R.id.button);
mButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent a= new Intent(Start.this,Timetable.class);
startActivity(a);
}
});
countDownStart();
}
public void countDownStart() {
handler = new Handler();
runnable = new Runnable() {
@Override
public void run() {
handler.postDelayed(this, 1000);
try {
SimpleDateFormat dateFormat = new SimpleDateFormat(
"yyyy-MM-dd");
// Please here set your event date//YYYY-MM-DD
Date futureDate = dateFormat.parse("2018-11-4");
Date currentDate = new Date();
if (!currentDate.after(futureDate)) {
long diff = futureDate.getTime()
- currentDate.getTime();
long days = diff / (24 * 60 * 60 * 1000);
diff -= days * (24 * 60 * 60 * 1000);
long hours = diff / (60 * 60 * 1000);
diff -= hours * (60 * 60 * 1000);
long minutes = diff / (60 * 1000);
diff -= minutes * (60 * 1000);
long seconds = diff / 1000;
txtDay.setText("" + String.format("%02d", days));
txtHour.setText("" + String.format("%02d", hours));
txtMinute.setText(""
+ String.format("%02d", minutes));
txtSecond.setText(""
+ String.format("%02d", seconds));
} else {
tvEventStart.setVisibility(View.VISIBLE);
tvEventStart.setText("The event started!");
textViewGone();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
handler.postDelayed(runnable, 1 * 1000);
}
public void textViewGone() {
findViewById(R.id.LinearLayout1).setVisibility(View.GONE);
findViewById(R.id.LinearLayout2).setVisibility(View.GONE);
findViewById(R.id.LinearLayout3).setVisibility(View.GONE);
findViewById(R.id.LinearLayout4).setVisibility(View.GONE);
findViewById(R.id.textViewheader1).setVisibility(View.GONE);
}}
`
发布于 2018-06-15 13:41:40
您可以简单地使用android中的CountDownTimer类来实现此功能。您可以在timer对象的onFinish()方法中启动xyzActivity
发布于 2018-06-15 13:46:53
int total;
long interval;
private int temp;
// declare before starting CountDownTimer
total = 3600 * hrs + 60 * min + sec;// outcome will be in seconds
interval = total * 1000;// outcome will be in milliseconds
CountDownTimer countDownTimer = new CountDownTimer(interval, 1000) {
int hours, minutes, seconds;
@Override
public void onTick(long millisUntilFinished) {
// when countdown counts
temp = total - 1;
hours = temp / 3600;
temp = temp - 3600 * hours;
minutes = temp / 60;
temp = temp - 60 * minutes;
seconds = temp;
total = 3600 * hours + 60 * minutes + seconds;
txtHour.setText("" + String.format("%02d", hours));
txtMinute.setText(""
+ String.format("%02d", minutes));
txtSecond.setText(""
+ String.format("%02d", seconds));
}
@Override
public void onFinish() {
// when the countdown completed intent to another application
}
}.start();发布于 2018-06-15 13:55:47
new CountDownTimer(300000, 1000) {
public void onTick(long millisUntilFinished) {
mTextField.setText("seconds remaining: " + millisUntilFinished / 1000);
}
public void onFinish() {
mTextField.setText("done!");
Intent intent = new Intent(MainActivity.this,NewActivity.class);
startActivity(intent);
}
}.start();https://stackoverflow.com/questions/50869478
复制相似问题