Note that there are some explanatory texts on larger screens.

plurals
  1. POpreventing android daily alarm from running the intent during alarm setup
    primarykey
    data
    text
    <p>I followed the instructions in <a href="https://stackoverflow.com/questions/7845660/how-to-run-a-service-every-day-at-noon-and-on-every-boot">this thread</a> to create a daily alarm that starts a service at 12:30 each day which shows a notification. The problem I'm having is that setting the alarm also triggers the service (=> and the notification) every time the app starts.</p> <p>Since I figured that the alarm will run only at the specified time (12:30) then I have no problem setting it when the app starts.</p> <p>I realize that setting the alarm from scratch every time the app is launched is a bit ineffective since it only needs to be set once (I made it set on device boot as well), but it seemed like the easiest way.</p> <p>So what's the best way to fix this? is there a way to set the alarm for the specified time without running the intent when setting?</p> <p>Here's the code if you are interested (this function is called every time when launching the app):</p> <pre><code>public static void setAlarm(Context context) { Intent intent = new Intent(context, AlarmReceiver.class); intent.setAction("com.Rani.app.SET_NOTIFICATION_ALARM"); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); Calendar dailyCheckTime = Calendar.getInstance(); dailyCheckTime.setTimeZone(TimeZone.getTimeZone("GMT")); dailyCheckTime.set(Calendar.HOUR_OF_DAY, 12); dailyCheckTime.set(Calendar.MINUTE, 30); AlarmManager alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarm.cancel(pendingIntent); alarm.setRepeating(AlarmManager.RTC_WAKEUP, dailyCheckTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); } </code></pre> <p>thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload