design patterns - Android widget change alarm interval -
i have created configure activity widget, user can choose various update frequencies.. until started alarm in onenabled() method, this:
intent intent = new intent(clock_widget_update); pendingintent pendingintent = pendingintent.getbroadcast(context, 0, intent, pendingintent.flag_update_current); alarmmanager alarmmanager = (alarmmanager) context.getsystemservice(context.alarm_service); alarmmanager.setrepeating(alarmmanager.rtc, system.currenttimemillis(), 1000 * 60, pendingintent);
the settings saved in shared preferences unique name (widgetid) , in onenabled() method can't retrieve settings here because can't widgetid yet. there's problem, user can change frequency anytime, method called once, @ beginning. think need start alarm in onupdate(), don't know how it, don't want make multiple instances of alarm accidentally ask advice.
to answer second problem, calling setrepeating multiple times not create multiple alarm far provide same pendingintent , same request code along pendingintent.flag_update_current flag. suggest use setinexactrepeating instead of setrepeating. can use same code in onupdate() new frequency. go through docs of flag_update_current , setinexactrepeating more detials.
Comments
Post a Comment