如何检查 AlarmManager setRepeating 触发的 Pending 意图是否已经在运行?

发布于 2024-12-10 11:39:38 字数 499 浏览 3 评论 0原文

我很高兴知道如何检查是否由警报管理器触发的待处理意图,该警报管理器在 AlarmManager.setRepeating 给出的特定时间启动活动?

更具体地说,我有一项活动以特定的设定时间或重复时间(有效)启动另一项活动。但我想知道用户是否已经设置了该请求?在这种情况下,我不应该开始某些值。

这就是我开始预定活动的方式。

Intent myIntent = new Intent(getBaseContext(),MyScheduledReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, myIntent, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), interval, pendingIntent);

I would be glad to know how to check if Pending intent which is triggered by an Alarm Manager which starts an activity at a specific time given by AlarmManager.setRepeating?

To be more specific, I have an activity which kicks off another activity with a paticular set time, or repeating time, (which works) . But i want to know if the request was already set by the user? in that case i should not start certain values.

This is how i start the scheduled activity.

Intent myIntent = new Intent(getBaseContext(),MyScheduledReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), 0, myIntent, 0);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), interval, pendingIntent);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生寂 2024-12-17 11:39:38

好吧,我想我已经找到了方法,

//CHECKING IF PENDING INTENT IS ALREADY RUNNING
Intent checkIntent = new Intent(getApplicationContext(),MyScheduledReceiver.class);
alarmUp = (PendingIntent.getBroadcast(getBaseContext(), 0, checkIntent, PendingIntent.FLAG_NO_CREATE) != null);

谢谢,希望它对某人有帮助......

Ok, I think i have managed to find out how,

//CHECKING IF PENDING INTENT IS ALREADY RUNNING
Intent checkIntent = new Intent(getApplicationContext(),MyScheduledReceiver.class);
alarmUp = (PendingIntent.getBroadcast(getBaseContext(), 0, checkIntent, PendingIntent.FLAG_NO_CREATE) != null);

Thanks, hope it might be helpful for someone...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文