Android AlarmManager and Service question

依然范特西╮ 提交于 2019-12-02 04:29:06

No you can't do that directly from listener. You can disable the alarm this way:

Intent intent = new Intent(maincode.this, AlarmReceiver.class);
PendingIntent pendingIntent =  PendingIntent.getBroadcast(bInsulinReminder.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
pendingItem.cancel();
alarmManager.cancel(pendingItem);

Or if (I suppose) AlarmReceiver is implementation of BroadcastReceiver and from onReceive method you start your MyService which is implementation of Service class.

So, if you want to stop this alarm from inside of your maincode.java listener you can just stop MyService by recreating PendingIntent you used in AlarmReceiver and executing stopService method.

Hope that helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!