Android - Alarm manager runs every day

前端 未结 2 1194
無奈伤痛
無奈伤痛 2021-01-25 01:21

I don\'t understand what\'s wrong but my alarm runs every single day even if I hardcode the day number, I have no idea whats going on...

Intent notificationInten         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-25 01:26

    Why is this line necessary?

    calendar.setTimeInMillis(System.currentTimeMillis());
    

    Also, the android development documentation recommends using

    setInexactRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation);
    

    EDIT: I suspect the intent isn't set for creating alarms so it's not creating the alarms correctly. Maybe this would work:

    Intent intent = new Intent(this, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
    intent, PendingIntent.FLAG_ONE_SHOT);
    
    AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
    //set repeating alarm here
    

    I hope that answers the question.

提交回复
热议问题