我有类MianActivity,允许用户从date和timePicker中选择日期和时间。用户可以选择日期和时间并按“设置提醒”。 当用户按下“设置提醒”按钮时,日期和时间将存储到我的数据库中。 我用当前系统毫秒检查数据库中的日期和时间,通知将显示日期和时间与系统1匹配的时间。我遇到的问题是它只检查一次,如果不匹配它将停止整个通知..任何方式使它总是检查??
这是来自用户的代码获取日期和时间:
Calendar calendar = Calendar.getInstance();
String message = editmsg.getText().toString(); //get String from textbox
//set DatePicker of user choosen
calendar.set(Calendar.MONTH, datePicker.getMonth());
calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth());
calendar.set(Calendar.YEAR, datePicker.getYear());
//set timePicker
calendar.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour());
calendar.set(Calendar.MINUTE, timePicker.getCurrentMinute());
//DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
//String date = df.format(calendar.getTime());
long date = calendar.getTimeInMillis();
之后我将调用2函数:
storeData(date,message);
checkReminder();
这是我的checkReminder类
long current = System.currentTimeMillis();
DatabaseHandler cdb = new DatabaseHandler(MainActivity.this);
cdb.open();
Cursor dateAll = cdb.getAllDate();
if(dateAll.moveToFirst()){
do {
Log.v("getting data","getting data");
long date = dateAll.getLong(1);
if(date== current){
matchDate(date);
}
} while (dateAll.moveToNext());
}
这是我的matchDate类
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
intent.setClass(MainActivity.this,MyNortification.class);
intent.putExtra("msg", message);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
//show notification when date & time meet.
alarmManager.set(AlarmManager.RTC_WAKEUP, date, pendingIntent);
希望有人帮助我......