title: My service does not stop
body: <p>i am using a service to run my server but when i call stopservice(). It does not do anything just restarts the service.Any help will be appriciated.and please tell me how to remove the notification of service when the service stops.
  this is my service code:</p>
  
  <p>{New Code}</p>
  
  <pre><code>public class ServerService extends Service {
      private boolean isRunning = false;
      String port;
  
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
            port = "10000";
  
          run(port);
  
          return (START_NOT_STICKY);
      }
  
      @Override
      public void onDestroy() {
          if (isRunning) {
  
              isRunning = false;
              stopForeground(true);
          }   }
  
      @Override
      public IBinder onBind(Intent intent) {
          return (null);
      }
  
      @SuppressWarnings("deprecation")
      private void run(String port) {
          if (!isRunning) {
  
              isRunning = true;
  
              Notification note = new Notification(R.drawable.ic_launcher,
                      "Server is successfully running",
                      System.currentTimeMillis());
              Intent i = new Intent(Intent.ACTION_VIEW,
                      Uri.parse("http://localhost:" + port));
  
  
              PendingIntent pi = PendingIntent.getActivity(this, 0, i, 0);
  
              note.setLatestEventInfo(this, "Ws Server", "Open http://localhost:"
                      + port, pi);
  
              startForeground(1337,note);
          }
      }
  
  
  
          }
  </code></pre>