Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have had a similar problem and perhaps it applies to you (hard to tell since the code you supplied is pretty hard to navigate).</p> <p>My issue was that applying multiple intents to the manager that evaluated as equal overrode the previous applications of that intent. See <a href="http://developer.android.com/reference/android/content/Intent.html#filterEquals(android.content.Intent)" rel="nofollow">http://developer.android.com/reference/android/content/Intent.html#filterEquals(android.content.Intent)</a> for what I mean by equivalence. As an example, I had a schedule that used the URI domy://thing, with extras that varied over each intent (I need to fire the same action with different arguments each time). Extras don't count in equivalence, so my alarms were getting overwritten by each other.</p> <p>To get around this, I stored a queue of my alarms in a separate file and when one fired, popped the next off the top and put that in the manager. Maybe that'll help you.</p> <p>UPDATE: No examples publicly visible, but try this (Trigger is a simple object containing a URI and a time it needs to be fired, scheduleDb is a class that extends SQLiteOpenHelper):</p> <pre><code> /** * Pops the next trigger off the queue, adds it to the alarm manager, and * stores it in the DB in case we need to cancel it later. */ private void scheduleNextTrigger() { Log.d(TAG, "Popping next trigger off queue"); Optional&lt;Trigger&gt; nextTrigger = scheduleDb.getNextTrigger(); if (!nextTrigger.isPresent()) { Log.d(TAG, "Trigger queue is empty"); return; } Trigger trigger = nextTrigger.get(); Log.d(TAG, "Scheduling new trigger " + trigger); PendingIntent operation = createPendingIntent(trigger); long timestamp = trigger.getTimestamp(); // Ensure the next item is in the future if (timestamp &gt; clock.currentTimeMillis()) { Log.v(TAG, "Found valid trigger: " + trigger); alarmManager.set(AlarmManager.RTC_WAKEUP, timestamp, operation); } scheduleDb.setScheduledTrigger(trigger); } private PendingIntent createPendingIntent(Trigger trigger) { // AlarmManager allows only one instance of each URI, and seems to randomly // delete bundled URI extras, so we'll encode the triggered URI and place it // on a constant stem Uri triggerUri = Uri.parse(TRIGGER_URI + "?" + Uri.encode(trigger.getUri())); Intent triggerIntent = new Intent(Intent.ACTION_VIEW, triggerUri); triggerIntent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); Log.d(TAG, "Created trigger intent " + triggerIntent); PendingIntent operation = PendingIntent.getService(this, 0, triggerIntent, 0); return operation; } </code></pre> <p>Hope that helps</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