我有一个在服务中运行的倒数计时器,在计时器启动后,它会启动一个活动。无论是否有锁定屏幕,活动都会唤醒屏幕显示。问题是,一旦计时器启动,启动活动并打开显示屏需要额外的13-27秒。我不知道它是否与倒数计时器有关,或者我没有正确打开屏幕显示。这是我的代码,任何帮助将不胜感激。
public class CountDownTime extends CountDownTimer {
/**
* @param millisInFuture The number of millis in the future from the call
* to {@link #start()} until the countdown is done and {@link #onFinish()}
* is called.
* @param countDownInterval The interval along the way to receive
* {@link #onTick(long)} callbacks.
*/
public CountDownTime(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long millisUntilFinished) {
long millis = millisUntilFinished;
int progress = (int) (millisUntilFinished/1000);
// this is the format which reads the time data from the user and makes it readable
hms = String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(millis),
TimeUnit.MILLISECONDS.toMinutes(millis) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(millis)),
TimeUnit.MILLISECONDS.toSeconds(millis) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis)));
CountDownAct.timeTextView.setText(hms);
CountDownAct.timeProgressBar.setProgress(progress);
Log.i("CountDownService", hms);
// if(progress <= 1000){
// CountDownAct.timeProgressBar.setProgress(0);
// Intent goBack = new Intent(getApplicationContext(), alarmtimefinished.class);
//
// goBack.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// goBack.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
//
//
// startActivity(goBack);
//
// }
}
@Override
public void onFinish() {
CountDownAct.timeProgressBar.setProgress(0);
// Intent intent = new Intent();
// intent.setAction("com.personalproject.peter.timerapp.CUSTOM_INTENT");
// intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
////
// sendBroadcast(intent);
Intent goBack = new Intent(getApplicationContext(), alarmtimefinished.class);
goBack.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
goBack.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(goBack);
// CountDownService.startService = true;
//
}
}
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarmtimefinished);
CountDownService.startService = true;
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD |
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
blink();
mediaPlayer = MediaPlayer.create(this, R.raw.extreme_clock_alarm);
mediaPlayer.start();
mediaPlayer.setLooping(true);
}