我有办法在调试时查看PendingIntent设备中活动s 的列表吗?
我开始使用AlarmManager,我想看看我的PendingIntents是否正确创建和删除.
看到其他PendingIntent的东西也很好,就像一个好奇心看一些应用程序是否正在做一些"额外的工作".
I am building an app that set 2 alarms for each day of the week (at a certain hour and minute), the alarms repeat week after week forever.
Now the point is: if the user changes the alarms, I will need cancel the previously set alarms.
Is there a way to simply cancel all the alarms set by my application ?
我在AlarmManager中询问了cancel()
当我设置闹钟时,我使用AlarmManger,这是我的代码
StringBuilder q = new StringBuilder()
.append(time).append(".")
.append(day);
String action = q.toString();
Intent AlarmIntent = new Intent(Edit_Contract.this, ReceiverContract.class);
AlarmIntent.setAction(action);
AlarmManager AlmMgr = (AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent Sender = PendingIntent.getBroadcast(Edit_Contract.this, 0, AlarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Run Code Online (Sandbox Code Playgroud)
然后,我想取消我设置的所有闹钟,我该怎么办
我想取消所有设置的闹钟......我已经搜索了很多并尝试了很多东西但没有任何效果......当我在2分钟后设置闹钟然后我取消它时,它仍然会2 分钟后开火..... 任何帮助将不胜感激。
创建警报的方法:
Intent intent = new Intent(c, AlarmReceiver.class);
intent.putExtra("task", task);
intent.putExtra("id", id);
PendingIntent pendingIntent = PendingIntent.getActivity(c, code, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager)c.getSystemService(Context.ALARM_SERVICE);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
Run Code Online (Sandbox Code Playgroud)
这是为了取消警报:
Intent intent = new Intent(c, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getActivity(c, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am = (AlarmManager)c.getSystemService(Context.ALARM_SERVICE);
am.cancel(pendingIntent);
Run Code Online (Sandbox Code Playgroud)