I have two Repeating alarms in my app each with different time and notifications. This alarms are called when the user registered a play card.
When the play card is registered this two alarms must notify the user each day.
1.) 2:30pm - Time to exceed
2.) 3:30pm - Time to comeback
Now the problem is each time I set the two alarms the alarms keeps firing right away but when i just set one alarm it works just fine.
The codes for the alarm
public void setAlarmRepeating()
{
player_database = new player_database(MainActivity.this);
Db_retrieve db = new Db_retrieve(MainActivity.this);
db.openDB();
c = player_database.queryData("select * from player_ID ORDER BY ID DESC");
try {
if (c != null && c.moveToNext()) {
Calendar calendar1=Calendar.getInstance();
calendar1.set(Calendar.HOUR_OF_DAY,14);
calendar1.set(Calendar.MINUTE,30);
calendar1.set(Calendar.MILLISECOND,0);
Intent intent=new Intent(MainActivity.this,Dog_alarm.class);
PendingIntent dog1=PendingIntent.getBroadcast(this,1,intent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm1=(AlarmManager)getSystemService(ALARM_SERVICE);
alarm1.setInexactRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),calendar1.getTimeInMillis(),dog1);
Calendar calendar2=Calendar.getInstance();
calendar2.set(Calendar.HOUR_OF_DAY,15;
calendar2.set(Calendar.MINUTE,30);
calendar2.set(Calendar.MILLISECOND,0);
Intent intent1=new Intent(MainActivity.this,Dog_alarm.class);
PendingIntent dog2=PendingIntent.getBroadcast(this,2,intent1,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarm2=(AlarmManager)getSystemService(ALARM_SERVICE);
alarm2.setInexactRepeating(AlarmManager.RTC_WAKEUP,System.currentTimeMillis(),calendar2.getTimeInMillis(),dog2);
}
else
{
Toast.makeText(MainActivity.this,"No pets registered",Toast.LENGTH_SHORT).show();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
Then on my BroadcastReceiver I did this
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager1=(NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
Intent dog_intent1=new Intent(context,HomeActivity.class);
PendingIntent dog_pending1=PendingIntent.getActivity(context, 1,dog_intent1, PendingIntent.FLAG_UPDATE_CURRENT);
Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder1=new NotificationCompat.Builder(context)
.setContentIntent(dog_pending1)
.setSmallIcon(R.drawable.ic_action_prof_breed_icon)
.setSound(uri)
.setContentTitle("Pentra")
.setContentText("Time to exceed")
.setAutoCancel(true);
notificationManager1.notify(1,builder1.build());
NotificationManager notificationManager2=(NotificationManager)context.getSystemService(context.NOTIFICATION_SERVICE);
Intent dog_intent2=new Intent(context,HomeActivity.class);
PendingIntent dog_pending2=PendingIntent.getActivity(context, 2,dog_intent2, PendingIntent.FLAG_UPDATE_CURRENT);
Uri uri1= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder2=new NotificationCompat.Builder(context)
.setContentIntent(dog_pending2)
.setSmallIcon(R.drawable.ic_action_prof_breed_icon)
.setSound(uri1)
.setContentTitle("Pentra")
.setContentText("Time to go back?")
.setAutoCancel(true);
notificationManager2.notify(2,builder2.build());
}
if you can look it up, please tell me what im doing wrong, been pondering about this for 1 day now and still don't know what is wrong.
Edit:
I tried to add this to check if the day sa pass or not
if(calendar1.before(Calendar.getInstance())) {
calendar1.add(Calendar.DATE, 1);
}
but still the alarm keeps firing away