Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'll post an example with a way I did it in one of the apps I created. </p> <p>When calling the alarm you need to send an extra id like this: Tmp is an object which has a unique ID. </p> <pre><code>Intent intent = new Intent(DisplayActivity.this,AlarmReciever.class); intent.setData(Uri.parse("timer:"+tmp.getId())); PendingIntent pendingIntent = PendingIntent.getBroadcast(DisplayActivity.this,1, intent, 0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(),pendingIntent); </code></pre> <p>and then you retrieve the id with this line: </p> <pre><code>Long.parseLong(intent.getData().getSchemeSpecificPart()) </code></pre> <p>When cancelling just create the same pending intent with the ID and call alarmmanager.cancel()</p> <p>Edit:</p> <p>To cancel the specific alarm on the item the user clicked on (here is where tmp.getId comes in handy) I just used this code, I think you need to create the same pendingIntent to be able to cancel the specific alarm. </p> <pre><code> Intent intent = new Intent(DisplayActivity.this,AlarmReciever.class); intent.setData(Uri.parse("timer:"+tmp.getId())); PendingIntent pendingIntent = PendingIntent.getBroadcast(DisplayActivity.this,1, intent, 0); AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); am.cancel(pendingIntent); </code></pre> <p>AlarmReciever is my BroadcastReceiver. DisplayActivity is the activity itself. </p> <p>It's in AlarmReciever I have the following code: </p> <pre><code>Long.parseLong(intent.getData().getSchemeSpecificPart()) </code></pre>
 

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