title: How to stop a service when a button in the layout for another activity is pressed
body: <p>I have a service that runs something every several seconds then sleeps until a certain time has elapsed. Not ideal, but effective for my purposes. I would like to have a button in the layout for NotifActivity start and stop the service called NotifService as requested. Here is basically what I have in NotifService:</p>
  
  <pre><code>public class NotifService extends IntentService {
  public NotifService() {
      super("NotifService");
  }
  
  @Override
  protected void onHandleIntent(Intent intent) {
      while(true){
          try {
              checkcalc();
              Thread.sleep(1000);
  
          } catch (InterruptedException e) {
              // Restore interrupt status.
              Thread.currentThread().interrupt();
          }
      }
  }
   public void checkcalc () {
      //some code I am trying to run
  }
  
  public void notifSend(String num){
  
      //Sends a notification
      }
  }
  </code></pre>
  
  <p>And the bit of NotifActivity that is called to start the service:</p>
  
  <pre><code>public void sendNotification(View view) {
      Intent serviceIntent = new Intent(this, NotifService.class);
      startService(serviceIntent);
  
  }
  </code></pre>
  
  <p>How would I now stop the service? stopService(serviceIntent) seems ineffective, so what do I have to do.</p>
  
  <p>Thanks!</p>