public void SetAlarm(Context context, int sec)
{
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0);
am.set(AlarmManager.RTC, System.currentTimeMillis()+1000*5 , pi);
i = new Intent(context, Alarm.class);
pi = PendingIntent.getBroadcast(context, 0, i, 0);
am.set(AlarmManager.RTC, System.currentTimeMillis()+1000*10 , pi);
}
Why onReceive works only once, after 10 seconds ?
Alarm manager would cancel the first alarm , since pending intent with same information has been provided to the alarm manager. Any alarm, of any type, whose Intent matches this one (as defined by filterEquals(Intent)), will be canceled.
If you want to set multiple alarms (repeating or single), then you just need to create their PendingIntents with different requestCode. If requestCode is the same, then the new alarm will overwrite the old one.
try with this…