Note that there are some explanatory texts on larger screens.

plurals
  1. POAlarmManager not stopping previous PendingIntent
    text
    copied!<p>I have a function where I set a <strong>15 minute</strong> repeating alarm to start my service, which calls a webservice, processes the result and closes. Simplified:</p> <pre><code>public static void setAlarm(Context cx) { try{ //My service is running, no need to reset the alarm if (isServiceRunning()) return; Intent intent = new Intent(cx, ResultService.class); PendingIntent sender = PendingIntent.getService(cx, 0, intent, PendingIntent.FLAG_NO_CREATE); //My pending intent exists, no need to reset the alarm if (sender!=null) return; sender = PendingIntent.getService(cx, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); AlarmManager am = (AlarmManager) cx.getSystemService(cx.ALARM_SERVICE); //Cancel any previous alarms???? am.cancel(sender); am.setRepeating(AlarmManager.RTC_WAKEUP, firstRun, interval, sender); }catch (Exception e){ } } </code></pre> <p>This is called by a BroadcastReceiver that listens for the following events</p> <pre><code>ACTION_SCREEN_ON ACTION_BOOT_COMPLETED CONNECTIVITY_ACTION </code></pre> <p>via </p> <pre><code>setAlarm(context.getApplicationContext()); </code></pre> <p>It seems to work however I start seeing multiple calls to my webservice <strong>per second</strong> on random devices.</p> <p>I have tried getting it to happen whilst debugging with no success. </p> <p>What am I doing wrong here?</p> <p><strong>Update</strong></p> <p>I ran </p> <pre><code>adb shell dumpsys alarm &gt; dump.txt </code></pre> <p>to check the alarm lock and I see the number of wakeups/alarms increases every time the alarm manager executes my PendingIntent:</p> <pre><code> com.x 279ms running, 22 wakeups 22 alarms: flg=0x4 cmp=com.x/.service.ResultService </code></pre> <p>Does it mean anything?</p> <p><strong>UPDATE 2</strong></p> <p>I tracked one of the offending devices.</p> <p>It calls the web service as it should for most of the day, then suddenly at 19:53 last evening I get 330 extra calls from the device in 6 seconds.</p> <p>Afterwards it runs fine until 06:50 this morning when I get 282 extra calls and on 06:55 I get another 130 extra calls.</p>
 

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