I have this goal setting app wherein in each activity of the goal set in the app is set with an alarm time and date.
For example:
Goal 1: A
Activity a1: nana
Deadline: 11/5/2015
Alarm Time: 9:00 am
Goal 2: B
Activity b1: hehe
Deadline: 11/5/2015
Alarm Time: 9:00 am
Only one of them is fired. I tried putting them different millisecond on each activity alarm time. But Its still the same. I want to them to be fired at the same time. I tried other sources and they suggest to use setExact() but i cant use that function cause its only for API 19 and above. My API is 17. And there's no problem when i set alarms with different time but the same date.
This is my code:
First, I put the alarm time set on an activity in the TABLE_ACTIVITIES.
public void setAlarm(){
Activities act = dbhandler.getActivity(actid);
// give them random millisecond
int min = 1;
int max = 1000;
Random r = new Random();
m = r.nextInt(max - min + 1) + min;
MessageTo.message(SetNotifyActivity.this,Integer.toString(m));
//the second is 0
dbhandler.updateActivityAlarm(hour,minute,0,m,goal_id,actid);
}
and then setting all the alarms in all activities the user made in each goal
public void setAlarms(){
List<Activities> allActs = dbhandler.getAllActivitiesByGoal(goal_id);
for (final Activities act : allActs) {
//for alarm
//Create an offset from the current time in which the alarm will go off.
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.DATE, Integer.parseInt(act.getEDay())); //1-31
cal.set(Calendar.MONTH, Integer.parseInt(act.getEMonth()) - 1); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR, Integer.parseInt(act.getEYear()));//year...
cal.set(Calendar.HOUR_OF_DAY, act.getHour());
cal.set(Calendar.MINUTE, act.getMinute());
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, act.getMillisecond());
//MessageTo.message(SetNotifyActivity.this, hour+":"+minute+" "+format);
//assigned a unique id to notifications
//Create a new PendingIntent and add it to the AlarmManager
Intent intent3 = new Intent(this, ViewTasksActivity.class);
intent3.putExtra("goalid", Integer.toString(goal_id));
intent3.putExtra("activityId", Integer.toString(act.getActId()));
intent3.putExtra("activityName", act.getActivityName());
intent3.putExtra("show", "true");
PendingIntent pendingIntent = PendingIntent.getActivity(this,
act.getActId(), intent3, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am =
(AlarmManager) getSystemService(Activity.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
pendingIntent);
}
}