我在我的应用程序中做提醒。用户可以设置提醒时间。如何做永久的服务,谁会检查设备的时间和是否等于用户设定的时间-输出通知。我试过这样做,但它工作了几次,然后就死了。我做错了什么?
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();
}
}}
发布于 2014-10-18 14:21:57
你不能做“永恒的服务”,这也不是解决这个问题的正确方法。actively delivering value to the user。观看时钟滴答没有主动地向用户传递价值。
使用AlarmManager来安排在执行提醒时获得控制。
https://stackoverflow.com/questions/26440732
复制相似问题