Title: Cancel Alarm and notification set in a Fragment from another Fragment
Tags: android;android-fragments;android-notifications;android-alarms
Question: I am trying to cancel an alarm set in a Fragment , from another Fragment, how I can do this?
InserisciOra.java  (the Fragment in which I set the alarm)
Intent myIntent = new Intent(getActivity(), MyReceiver.class);
if(PendingIntent.getBroadcast(getActivity(), 0,
myIntent,
PendingIntent.FLAG_NO_CREATE) == null){
pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, myIntent,0);
alarmManager = (AlarmManager)getActivity().getSystemService(Context.ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
Comment: @Fahim  yes  both fragment are of same activity

Comment: Actually not, but I will add other Alarms

Comment: both fragment are of same activity?

Comment: do you  have multiple Alarm/notifications?

Here is the accepted answer: Intent myIntent = new Intent(getActivity(), MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(getActivity(), 0, myIntent,0);
alarmManager = (AlarmManager)getActivity().getSystemService(Context.ALARM_SERVICE);
// cancel the alarm
alarmManager.cancel(pendingIntent);
// delete the PendingIntent
pendingIntent.cancel()
Comment for this answer: Thank's David , i tried your code but when i cancel my alarm and then I set it ,the alarm don't work :(
Comment for this answer: Yes the problem was that I didn't delete the PendingIntent , thank you very much!!!!
Comment for this answer: Please explain what you mean. Maybe you also didn't delete the `PendingIntent` so that the code you use to determine whether or not the alarm is still set probably doesn't work. I'll edit my answer.

Here is another answer: use cancel method to cancel your alarm
Intent myIntent = new Intent(getActivity().,
MyReceiver.class);
PendingIntent pendingIntent
= PendingIntent.getBroadcast(getActivity(),
0, myIntent, 0);
AlarmManager alarmManager
= (AlarmManager)getActivity().getSystemService(ALARM_SERVICE);
alarmManager.cancel(pendingIntent);
Comment for this answer: where I have to put this code? In the Fragment without anything else?
Comment for this answer: the problem is that i just want to reset the alarm, in this way the alarm is deleted and I can't set a new alarm in the future
Comment for this answer: ofcourse you can set it again. the same way how you are doing it right now

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:03/23/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><android-fragments><android-notifications><android-alarms>', 'Title': 'Cancel Alarm and notification set in a Fragment from another Fragment', 'ViewCount': 697, 'id': 29205604, 'user_AboutMe': None, 'user_AccountId': 5827587.0, 'user_DisplayName': 'Slaiv206', 'user_Reputation': 309.0, 'user_Views': 31.0, 'user_id': 4593347.0}}