I am trying to set alarm for my courses. I need to kick of alarm 1 hour before they start. So I just want
- get week of year
- look through the weeks (loop ...51,52)
- look through the classes (loop ...n)
- set the day of week for this class
- set the hour of day one hour before this class
- set the minute to 00
- set alarm using this calendar instance
- end of loop (classes)
- set the week to one week from current week
- look through the classes (loop ...n)
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
for (int i = cal.get(Calendar.WEEK_OF_YEAR); i <= 52; i++) {
for (Dersler d : dersProgrami) {
alarm = new DersAlarmi(String.valueOf(d.getBaslangicS()) + "00", d.getDersAdi(), d.getDerslik());
cal.set(Calendar.DAY_OF_WEEK, d.getDayOfClass()+1);
cal.set(Calendar.MINUTE, 00);
cal.set(Calendar.HOUR_OF_DAY, d.getStartHour());
cal.add(Calendar.HOUR_OF_DAY, -1);
Log.i("ALARM KURULDU",
String.valueOf(i) + String.valueOf(cal.get(Calendar.DAY_OF_MONTH))+"."+String.valueOf(cal.get(Calendar.MONTH))+"."+String.valueOf(cal.get(Calendar.YEAR))+" "+String.valueOf(cal.get(Calendar.HOUR_OF_DAY))+":"+String.valueOf(cal.get(Calendar.MINUTE))+" Ders:" + d.getDersAdi()
+ " Hafta:"
+ cal.get(Calendar.WEEK_OF_YEAR) + " Gün:"
+ cal.get(Calendar.DAY_OF_WEEK) + " Saat:"
+ cal.get(Calendar.HOUR_OF_DAY));
alarmManager.set(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(), pendingIntent);
dersAlarmlari.add(alarm);
}
cal.set(Calendar.WEEK_OF_YEAR, cal.get(Calendar.WEEK_OF_YEAR)+1);
}
Current date time is: 23.04.2012 23:37
Logcat is:
04-23 23:23:10.835: I/ALARM KURULDU(16380): 17 25.3.2012 14:0 Ders:DATA MINING Hafta:17 Gün:4 Saat:14
04-23 23:23:10.835: I/ALARM KURULDU(16380): 17 23.3.2012 8:0 Ders:Database Management and SQL Hafta:17 Gün:2 Saat:8
04-23 23:23:10.855: I/ALARM KURULDU(16380): 17 25.3.2012 12:0 Ders:ENTREPRENEURSHIP Hafta:17 Gün:4 Saat:12
04-23 23:23:10.865: I/ALARM KURULDU(16380): 1723.3.2012 11:0 Ders:GRADUATION PROJECT Hafta:17 Gün:2 Saat:11
04-23 23:23:10.865: I/ALARM KURULDU(16380): 18 25.3.2012 14:0 Ders:DATA MINING Hafta:17 Gün:4 Saat:14
04-23 23:23:10.885: I/ALARM KURULDU(16380): 18 23.3.2012 8:0 Ders:Database Management and SQL Hafta:17 Gün:2 Saat:8
04-23 23:23:10.885: I/ALARM KURULDU(16380): 18 25.3.2012 12:0 Ders:ENTREPRENEURSHIP Hafta:17 Gün:4 Saat:12
04-23 23:23:10.895: I/ALARM KURULDU(16380): 18 23.3.2012 11:0 Ders:GRADUATION PROJECT Hafta:17 Gün:2 Saat:11
04-23 23:23:10.905: I/ALARM KURULDU(16380): 19 25.3.2012 14:0 Ders:DATA MINING Hafta:17 Gün:4 Saat:14
...
So why does it say its 23.03.2012 or 25.03.2012 in the logcat instead of todays date 23.04.2012? I have been wasting my hours for this, can anybody tell me the right way to set the alarms please?