Currently I've got this code:
public static void setupAlarm(Context context) {
Intent myIntent = new Intent(context, Receiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, myIntent, PendingIntent.FLAG_NO_CREATE);
if (pendingIntent != null) {
return;
} else {
pendingIntent = PendingIntent.getBroadcast(context, PENDING_INTENT_RETRY, myIntent,
PendingIntent.FLAG_ONE_SHOT);
}
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.MINUTE, 2);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}
What I want is to use pending intent one time and wait for the fire. If in the meantime someone asks for a new alarm, if the alarm exist I don't want to setup anything. Now my question: after the first alarm, the pending intent is deleted due to the ONE_SHOT flag, but can I create the pending intent again or not?