I am trying to use Androids AlarmManager. The problem is, it fires twice right after one another.
public class ScheduleSomething {
public static void schedule(Pojo pojo) throws JsonProcessingException {
final ObjectMapper mapper = new ObjectMapper();
final String pojoAsJson = mapper.writeValueAsString(pojo);
final Intent alarmIntent = new Intent(MyApplication.getAppContext(),
PojoAlarmReceiver.class);
alarmIntent.putExtra(POJO_AS_JSON, pojoAsJson);
final PendingIntent pi = PendingIntent.getBroadcast(MyApplication.getAppContext(), 0,
alarmIntent, PendingIntent.FLAG_ONE_SHOT);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + pojo.getScheduledTime() + 10L, pi);
}
}
public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// do stuff. onReceive() is being called twice, every time.
}
}
Ofcourse I have checked if I call the schedule(Pojo pojo) method twice but sadly, that's not it. Right now, I work around this but sooner or later, I'd like to resolve this in a clean way. Best regards and hopefully someone knows what's going wrong.