永恒的提醒服务

时间:2014-10-18 14:19:30

标签: java android service reminders

我在我的应用中提醒。用户可以设置提醒时间。如何进行永久性服务,谁将检查设备时间以及是否等于用户设置时间 - 输出通知。我尝试这样,但它工作几次并死亡。我做错了什么?

void redinder2() {    

for (int i = 1; i<=10; i++) {

  Calendar calendar = Calendar.getInstance();    
  hour = calendar.get(Calendar.HOUR_OF_DAY);
  minute = calendar.get(Calendar.MINUTE);   

  if(hour==my_hour&&minute==my_minyte){){    sendNotif();}      

      if(i==10){startService(new Intent(this, MyService.class));}
          try {
            TimeUnit.SECONDS.sleep(59);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
}

}

1 个答案:

答案 0 :(得分:0)

你不能做出永恒的服务&#34;,也不是解决这个问题的正确方法。 Only have a service running when it is actively delivering value to the user。观察时钟标记并不能主动为用户提供价值。

使用AlarmManager安排获取控制权以进行提醒。