我是 Android 开发的新手。目前我正在开发待办事项应用程序。
在这个应用程序中,我正在使用 Pending Intent 设置通知。在这我使用AlarmManager。设置警报后,通知会在准确的时间发生。
注意:在待定意图中,我使用了唯一 ID。(这里唯一 ID 表示从数据库中获取行记录 ID)。
我的问题是,当我更新AlarmManager时,通知没有及时到来。它在我更新AlarmManager之后出现。
我的更新代码是:
private void updateAlarm(int year,int month,int date,int hour,int minute,int second,String event_id,String e_desc)
{
AlarmManager alarmManager = (AlarmManager) this.getSystemService(this.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.set(year, month-1, date, hour, minute, second);
long when = calendar.getTimeInMillis(); // notification time
String event_desc = e_desc;
Intent intent = new Intent(this, ReminderContent.class);
intent.putExtra("EventDesc", e_desc);
int alarm_id = Integer.valueOf(event_id);
//alarm_id is the Id of PendingIntent which is already created.
PendingIntent pendingInt = PendingIntent.getBroadcast(this, alarm_id , intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.set(AlarmManager.RTC, when, pendingInt);
}
我的更新AlarmManager的程序是否正确?