title: Alarm Manager & Broadcast receiver not stopping
body: <p>I want to create notifications on multiple specific dates &amp; time, which are stored in database. I can get Notifications on correct date and time, but what i noticed later is, that i also got notifications randomly on the next day. They keep cropping up whenever i restart the emulator. </p>
  
  <p>So, it seems that i can't stop the Alarm manager or Broadcast receiver. I've tried with providing pendingIntent to alarmmanager's cancel method to no avail. I also use toggle button to enable/disable notification, but it has no effect</p>
  
  <p>Below is my code.</p>
  
  <p>MainActivity.java</p>
  
  <pre><code>PendingIntent pendingIntent;
      AlarmManager alarmManager;
      Button set, cancel;
      MTPAdapter db;
      ArrayList&lt;TourPlan&gt; arrDates;
  
      ToggleButton toggle;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
          toggle = (ToggleButton) findViewById(R.id.toggleButton1);
  
                  // This function fetched data from DB
          fetchDates();
  
  
  
          set = (Button) findViewById(R.id.the_button);
          cancel = (Button) findViewById(R.id.the_button_cancel);
          cancel.setEnabled(false);
  
  
  
          toggle.setOnCheckedChangeListener(new OnCheckedChangeListener() {
  
              @Override
              public void onCheckedChanged(CompoundButton buttonView,
                      boolean isChecked) {
                  // TODO Auto-generated method stub
                  if (isChecked) {
                      Toast.makeText(getApplicationContext(), "Set",
                              Toast.LENGTH_SHORT).show();
                      setEvent();
                  } else {
                      alarmManager.cancel(pendingIntent);
                      MyReceiver.stopService(getApplicationContext());
                  }
              }
          });
      } // end onCreate
  
      public void setEvent() {
  
          for (int i = 0; i &lt; arrDates.size(); i++) {
              // int id = arrDates.get().getId();
  
              int year = Integer.parseInt(arrDates.get(i).getYear());
  
              int month = Integer.parseInt(arrDates.get(i).getMonth());
  
              int date = Integer.parseInt(arrDates.get(i).getDate());
  
              int hour = Integer
                      .parseInt(firstStringer(arrDates.get(i).getTime()));
              Log.v("Hour : ", "" + hour);
  
              int minute = Integer.parseInt(stringer(arrDates.get(i).getTime()));
              Log.v("minute : ", "" + minute);
              int second = 00;
              startAlarm(i, year, month, date, hour, minute, second);
          }
      }
  
      public void startAlarm(int id, int year, int month, int date, int hour,
              int minute, int second) {
          Calendar calendar = Calendar.getInstance();
  
          calendar.set(Calendar.MONTH, month);
          calendar.set(Calendar.YEAR, year);
          calendar.set(Calendar.DAY_OF_MONTH, date);
  
          calendar.set(Calendar.HOUR_OF_DAY, hour);
          calendar.set(Calendar.MINUTE, minute);
          calendar.set(Calendar.SECOND, 0);
          // calendar.set(Calendar.AM_PM, Calendar.PM);
  
          Intent myIntent = new Intent(MainActivity.this, MyReceiver.class);
  
          pendingIntent = PendingIntent.getBroadcast(MainActivity.this, id,
                  myIntent, 0);
  
          alarmManager.set(AlarmManager.RTC, calendar.getTimeInMillis(),
                  pendingIntent);
      }
  
  
      }
  </code></pre>
  
  <p>MyAlarmService.java</p>
  
  <pre><code>public class MyAlarmService extends Service {
  
  
      @Override
      public IBinder onBind(Intent arg0) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public void onCreate() {
          // TODO Auto-generated method stub
          super.onCreate();
      }
  
      @SuppressWarnings("static-access")
      @Override
      public void onStart(Intent intent, int startId) {
          super.onStart(intent, startId);
  
  
  
          NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                  this)
                  .setSmallIcon(R.drawable.ic_launcher)
                  .setContentTitle("ISFA")
                  .setStyle(
                          new NotificationCompat.BigTextStyle()
                                  .bigText("Tour Planned for the Day"))
                  .setContentText("You have planned a tour for today")
                  .setAutoCancel(true);
  
          mBuilder.setContentIntent(contentIntent);
          mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
      }
  
      @Override
      public void onDestroy() {
          // TODO Auto-generated method stub
          super.onDestroy();
      }
  </code></pre>
  
  <p>MyReceiver.java (Broadcast receiver) :</p>
  
  <pre><code>  public class MyReceiver extends BroadcastReceiver {
  
              @Override
              public void onReceive(Context context, Intent intent) {
  
                  Intent service1 = new Intent(context, MyAlarmService.class);
                  context.startService(service1);
  
              }
  
              public static void stopService(Context context) {
                  Intent stopServiceIntent = new Intent(context, MyAlarmService.class);
                  context.stopService(stopServiceIntent);
              }
          }
  </code></pre>
  
  <p>Manifest file:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /&gt;
  </code></pre>
  
  <p>In Application tags,</p>
  
  <pre><code> &lt;service
             android:name="com.example.brodcastalarm.MyAlarmService"
             android:enabled="true" /&gt;
     &lt;!-- THE BROADCAST RECIEVER WHICH MANAGES THE BROADCAST FOR NOTIFICATION --&gt;
              &lt;receiver android:name="com.example.brodcastalarm.MyReceiver" &gt;
                  &lt;intent-filter&gt;
                      &lt;action android:name="android.intent.action.BOOT_COMPLETED" /&gt;
                  &lt;/intent-filter&gt;
              &lt;/receiver&gt;
  </code></pre>
  
  <p>This is the Database structure.
  I use subString methods to get hour and minutes.</p>
  
  <p><img src="https://i.stack.imgur.com/RZIQU.png" alt="This is Database Sample"></p>