更确切地说,我想做以下事情:AlarmReceiver-Broadcaster应该每天执行两次:TimerTask仍然是更好的解决方案吗?
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 18);
calendar.set(Calendar.MINUTE, 54);
Intent intentAlarm = new Intent(context, AlarmReceiver.class);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
PendingIntent.getBroadcast(context, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 17);
calendar.set(Calendar.MINUTE, 58);
Intent intentAlarm2 = new Intent(context, AlarmReceiver.class);
AlarmManager alarmManager2 = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager2.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
PendingIntent.getBroadcast(context, 1, intentAlarm2, PendingIntent.FLAG_UPDATE_CURRENT));