You have to assume that the functions already have an instance of AlarmManager.
"AlarmManager alarms = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE)" But yeah, I just need to know if I'm setting it up correctly. On Jan 6, 3:02 pm, Kristopher Micinski <[email protected]> wrote: > Sorry, now see you've at least heard of the class :-), but you don't > seem to be using it in the standard way.., usually you will set an > alarm using the alarm manager. > > kris > > On Fri, Jan 6, 2012 at 2:01 PM, Kristopher Micinski > > > > > > > > <[email protected]> wrote: > > Have you heard of AlarmManager? > > >http://developer.android.com/resources/samples/ApiDemos/src/com/examp... > > >http://developer.android.com/reference/android/app/AlarmManager.html > > > Kris > > > On Fri, Jan 6, 2012 at 1:38 PM, Diego Tori > > <[email protected]> wrote: > >> After reading lots of sample code into this matter, I'm trying to > >> figure out the simplest way to achieve the following: > > >> I want to be able to schedule an Intent that calls back to my Alarm > >> BroadcastReceiver, which in turn fires off my Service. However, I want > >> to set up so that it calls said Intent twice a day and to only > >> schedule the alarms if they haven't already been set (likewise for > >> canceling the alarms). > > >> However, I am unsure if the following code is the correct way to set > >> and cancel alarms. > > >> //Static function for setting the alarm > >> //My midday calendar object (cal1) > > >> ... > > >> //My evening calendar object (cal2) > > >> Intent myIntent = new Intent(context, MyAlarmReceiver.class); > > >> PendingIntent firstCallIntent = > >> PendingIntent.getBroadcast(context, FIRST_CALL_ID, myIntent, > >> PendingIntent.FLAG_NO_CREATE); > >> PendingIntent secondCallIntent= > >> PendingIntent.getBroadcast(context, SECOND_CALL_ID, myIntent, > >> PendingIntent.FLAG_NO_CREATE); > >> if(firstCallIntent != null){ > >> if(DEBUG){ > >> Log.d(TAG, "Setting Midday Alarm"); > >> } > >> firstCallIntent = PendingIntent.getBroadcast(context, > >> FIRST_CALL_ID, myIntent, 0); > >> alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, > >> cal1.getTimeInMillis(), AlarmManager.INTERVAL_DAY, firstCallIntent); > >> } > >> if(secondCallIntent != null){ > >> if(DEBUG){ > >> Log.d(TAG, "Setting Evening Alarm"); > >> } > >> secondCallIntent = PendingIntent.getBroadcast(context, > >> SECOND_CALL_ID, myIntent, 0); > >> alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, > >> cal2.getTimeInMillis(), AlarmManager.INTERVAL_DAY, secondCallIntent); > >> } > > >> //Static call to cancel the alarm. > > >> Intent myIntent = new Intent(context, MyAlarmReceiver.class); > >> PendingIntent firstCallIntent = > >> PendingIntent.getBroadcast(context, FIRST_CALL_ID, myIntent, 0); > >> alarms.cancel(firstCallIntent); > >> firstCallIntent.cancel(); > >> PendingIntent secondCallIntent = > >> PendingIntent.getBroadcast(context, SECOND_CALL_ID, myIntent, 0); > >> alarms.cancel(secondCallIntent); > >> secondCallIntent.cancel(); > > >> -- > >> 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 -- 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

