On Sat, Jul 16, 2011 at 1:14 PM, cathal coffey <[email protected]> wrote: >>When the alarm period changes, have your alarm-handling logic cancel the >>existing alarm and schedule a new one. > Okay but this is my question, how do I do this?
Call cancel() on AlarmManager. Then call setRepeating() on AlarmManager. > My AppWidget's Button > fires the below logic when it is pressed. > > AlarmManager mgr = > (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); > Intent i = new Intent(context, OnAlarmReceiver.class); > PendingIntent pi = PendingIntent.getBroadcast(context, 0, i, 0); > mgr.setRepeating(AlarmManager.ELAPSED_REALTIME, > SystemClock.elapsedRealtime(), 1000, pi); > mgr.cancel(pi); Which means the above cancel() and setRepeating() calls go in the onReceive() of OnAlarmRecevier, or possibly in an IntentService that is started by onReceive() of OnAlarmReceiver. > There is no way to detect when the alarm period should change because > there is no way to communicate between the Alarm's fired function and > the AppWidgets non-existent state. Sure there is. onReceive() of OnAlarmReceiver needs two pieces of information: -- the time when the state should change -- what the new state is where by "state" I mean the new alarm period, how long it should remain on that period, etc. Just a classic state machine. You can either attach that information as extras on the Intent you use with the PendingIntent for the alarm itself (in which case onReceive() gets those extras off the supplied Intent), or you store that information in a file/database/SharedPreferences and read it in in onReceive(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

