这是我的代码,当我在本地数据库中插入时间和日期字符串时,我在本地数据库中插入的时间也设置了警报接收器,但问题是当我插入过去的时间和日期字符串时在数据库中,它将在当前时间触发,而时间已经过去。它适用于最新的时间和日期字符串
Calendar calender = Calendar.getInstance();
calender.clear();
calender.set(Calendar.MONTH, pickerDate.getMonth());
calender.set(Calendar.DAY_OF_MONTH, pickerDate.getDayOfMonth());
calender.set(Calendar.YEAR, pickerDate.getYear());
calender.set(Calendar.HOUR, pickerTime.getCurrentHour());
calender.set(Calendar.MINUTE, pickerTime.getCurrentMinute());
calender.set(Calendar.SECOND, 00);
SimpleDateFormat formatter = new SimpleDateFormat(getString(R.string.hour_minutes));
String timeString = formatter.format(new Date(calender.getTimeInMillis()));
SimpleDateFormat dateformatter = new SimpleDateFormat(getString(R.string.dateformate));
String dateString = dateformatter.format(new Date(calender.getTimeInMillis()));
AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), AlarmReceiver.class);
String alertTitle = mTitleText.getText().toString();
intent.putExtra(getString(R.string.alert_title), alertTitle);
// broadcastCode++;
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), broadcastCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
broadcastCode+=1;
alarmMgr.setExact(AlarmManager.RTC_WAKEUP, calender.getTimeInMillis(), pendingIntent);
cv.put(mDbHelper.TIME, timeString);
cv.put(mDbHelper.DATE, dateString);
db.insert(mDbHelper.TABLE_NAME, null, cv);