android - AlarmManager onReceive constantly goes off -
i've created broadcastreceiver following method :
public void setalarm(context context, int repeatinghours) { int repeatingtimeinmillis = 1000 * 60 * 60 * repeatinghours; // millisec * second * minute * hours x time between each alarm. alarmmanager am=(alarmmanager)context.getsystemservice(context.alarm_service); intent = new intent(context, autoupdatereceiver.class); pendingintent pi = pendingintent.getbroadcast(context, 0, i, 0); am.setrepeating(alarmmanager.rtc_wakeup, system.currenttimemillis()* repeatingtimeinmillis, repeatingtimeinmillis, pi); toast.maketext(context, "alarm set repeat every " + repeatinghours + " hours", toast.length_short).show(); } however call setalarm seems onreceive goes off.
this call setalarm if in way relevant :
receiver = new autoupdatereceiver(); howoftenradiogroup.setoncheckedchangelistener(new android.widget.radiogroup.oncheckedchangelistener() { @override public void oncheckedchanged(radiogroup group, int checkedid) { sharedpreferences prefeditor = getsherlockactivity().getsharedpreferences("com.kamstrup.ecamp", context.mode_private); int repeatinghours = 0; switch(checkedid) { case r.id.auto_update_radio_hour_1: repeatinghours = 1; prefeditor.edit().putint(settings_key, repeatinghours).commit(); break; case r.id.auto_update_radio_hour_3: repeatinghours = 3; prefeditor.edit().putint(settings_key, 3).commit(); break; case r.id.auto_update_radio_hour_6: repeatinghours = 6; prefeditor.edit().putint(settings_key, 6).commit(); break; case r.id.auto_update_radio_hour_12: repeatinghours = 12; prefeditor.edit().putint(settings_key, 12).commit(); break; default: break; } receiver.setalarm(getsherlockactivity(), repeatinghours); } }); why happening?
the issue see using int type repeatingtimeinmillis. should using long type timestamps. int's capacity not enough, may have overflow turning period in negative number.
also
system.currenttimemillis()* repeatingtimeinmillis definitely seems incorrect. shold add time offset current time, not multiply it.
Comments
Post a Comment