title: Android How to stop AlarmManager in other Activity
body: <p>I am using a service which is called in Activity 'A' repeatedly created by AlarmManager. My service is checking repeatedly response from server, when response is true new Activity B is started. Now when activity B is started i want to stop service as well as AlarmManager. how can i do this??</p>
  
  <p>my 'A' activity code for calling service is following</p>
  
  <pre><code>    Calendar cal = Calendar.getInstance();
      cal.add(Calendar.SECOND, 40);
  
      Intent intent = new Intent(this, response.class);
  
      // Add extras to the bundle
      intent.putExtra("foo", "bar");
      // Start the service
      // startService(intent);
  
      pintent = PendingIntent.getService(this, 0, intent, 0);
  
      alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
      int i;
      i = 15;
      alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
              i * 1000, pintent);
  
      startService(intent);
  </code></pre>
  
  <p>I have also tried this code snippet in Activity 'B' to stop AlarmManager but fail</p>
  
  <pre><code>      Intent sintent = new Intent(this, response.class);
       pintent = PendingIntent.getService(this, 0, sintent, 0);
       alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
       stopService(sintent);
       alarm.cancel(pintent);
  </code></pre>