Er_
Er_

Reputation: 23

AlarmManager run

I have a AlarmManager that run at the 20:00, but also run when i click the button for fix it. I only want that run at the 20:00

Calendar c = Calendar.getInstance();
c.set(Calendar.HOUR_OF_DAY, 20);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
AlarmManager a = (AlarmManager)getSystemService(ALARM_SERVICE);
a.setRepeating(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),AlarmManager.INTERVAL_DAY,p);

Upvotes: 0

Views: 216

Answers (1)

vadher jitendra
vadher jitendra

Reputation: 590

Put Below code in your code for repeating alarm at specific time

    if(System.currentTimeMillis() <= c.getTimeInMillis()){

        AlarmManager a = (AlarmManager)getSystemService(ALARM_SERVICE);
        a.setRepeating(AlarmManager.RTC_WAKEUP,c.getTimeInMillis(),AlarmManager.INTERVAL_DAY,p);

    }

i hope it helps you...

Upvotes: 1

Related Questions