我的应用程序是一个闹钟类型的应用程序的计时器。 当计时器到期时,如果用户已离开,但该应用程序仍在运行,我希望将应用程序的主要活动重新放入视图中。带回应用程序
我告诉我哪里想放置必要的代码:
public class MyCount extends CountDownTimer {
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
public void onFinish() {
/** code here to bring the app back to the front/top of stack, in its current state */
timeDisplay.setText("Expired.!");
ReminderFlashingScreen.setVisibility(View.GONE);
statustab.setBackgroundResource(R.drawable.redtab);
seeker.setProgress(0);
reset.setBackgroundResource(R.drawable.resetbtnoff);
playExpiredAlarm();
alarmAnimation.start();
flasher.setVisibility(View.VISIBLE);
StopAlarmButtonAnimation.start();
StopAlarmButton.setVisibility(View.VISIBLE);
expired = true;
}
public void onTick(long millisUntilFinished) {
remindertimepref = prefs.getString("reminderTime", "<unset>");
remindtime = Integer.parseInt(remindertimepref.trim());
timeDisplay.setText(formatTime(millisUntilFinished));
seeker.setProgress((int) (millisUntilFinished/1000/60) + 1);
if (used == true){
reminder_time = ((int) (millisUntilFinished/1000));
if (reminder_time == remindtime){
reminderalarm();
used = false;
}
}
}
}
?我的观点是,我想你想把你的计时器变成一项服务。然后,您可以发送您的应用程序在定时器完成时正在监听的广播。更简单,更清洁! – codinguser 2010-12-11 11:16:59
我需要阅读的东西..新的android,我的第一个想法是:如果应用程序被杀害,什么保持计数..?我知道如何保存当前状态,但没有任何用处,因为定时器会暂停。你的解决方案听起来像我应该探索的路线,任何我应该寻找/寻找的指针,赞赏。 – 11Monkeys 2010-12-11 11:27:38
考虑使用android AlarmManager http://developer.android.com/intl/de/reference/android/app/AlarmManager.html,而不是跟踪自己的时间,至少在您收到onPause呼叫后使用它。这将为用户节省大量的电池和CPU使用量。 – Janusz 2010-12-11 12:56:07