我想让我的应用程序每天都设置警报,让我们说早上7点是用户的药片列表。到目前为止,当用户添加新药时,我一直这样做,我会直接设置闹钟,但我想让它仅为今天设置闹钟。我有一天能够使用xpath得到药片列表,并将药片列入清单。现在我在想是否可以通过某种隐藏的活动来保持运行或者设置日常药丸。如果有人能给我指示我应该寻找什么来解决这个问题,我们将不胜感激。
答案 0 :(得分:0)
您应该使用:Alarm Manager。并将其放在Service中。另请阅读BroadcastReceiver
答案 1 :(得分:0)
我会为此提出一个想法。
使用Alarm
的设置方法在早上7点安排第一个AlarmManager
并注册BroadcastReceiver
以便在早上7点执行使用相同的AlarmManager
。
早上7点,您的Alarm
和BroadcastReceiver
将会执行。在您onReceive
的{{1}}方法中再次设置BroadcastReceiver
和Alarm
,使其成为自循环。
设置broadcastReceiver类的伪代码:
BroadcastReceiver
broadcastReceiver.class:
Intent intent = new Intent(this, broadcastReceiver.class);
intent.putExtra("subject", subject);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this,
0, intent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager am= (AlarmManager) getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, "Your specific time", pendingIntent);