java - Weird AlarmManager behaviour -


i have 2 broadcastreceivers , 2 intents, want click button, 5m later start broadcast1 , 10m later start broadcast2, what's happening both start 10m after click, guess is, intents not unique, i'm setting diffrent reqeustcode each of them.

button's onclick:

    bundle bd = new bundle();     bd.putint("mint", i);      intent intent1 = new intent(getactivity(), broadcast_1.class);     intent1.putextras(bd);     pendingintent pendingintent1 = pendingintent.getbroadcast(getactivity().getapplicationcontext(), i, intent1, pendingintent.flag_update_current);     alarmmanager alarmmanager1 = (alarmmanager) getactivity().getapplicationcontext().getsystemservice(context.alarm_service);     alarmmanager1.setrepeating(alarmmanager.rtc, system.currenttimemillis()+1000*60*5, 1000*60*10, pendingintent1);     toast.maketext(getactivity(), "countdown started "+i ,toast.length_short).show();      intent intent2 = new intent(getactivity(), broadcast_1.class);     intent2.putextras(bd);     pendingintent pendingintent2 = pendingintent.getbroadcast(getactivity().getapplicationcontext(), i+42212342, intent2, pendingintent.flag_update_current);     alarmmanager alarmmanager2 = (alarmmanager) getactivity().getapplicationcontext().getsystemservice(context.alarm_service);     alarmmanager2.setrepeating(alarmmanager.rtc, system.currenttimemillis()+1000*60*10, 1000*60*10, pendingintent2); 

broadcastreceiver_1 , _2 (they same) class:

public class broadcast_1 extends broadcastreceiver {      @override     public void onreceive(context context, intent intent) {          calendar c = calendar.getinstance();         int seconds = c.get(calendar.second);         int minutes = c.get(calendar.minute);         showtextfragment.settext("broadcast_1" + " @ " + minutes + " : " + seconds);      }  } 

question: why recent intent push previous intents starting time?

i confirmed behaviour printing time when broadcast's code executes. please help

the problem seeing way repeating alarms work. in order preserve battery life, alarmmanager takes great liberties in rescheduling alarms in order group multiple alarms together. basically, if need sort of accurate timing should forget using setrepeating(). use setexact() instead. if need repeating alarm, reset when goes off.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo