title: How to stop service even after restarting activity?
body: <p>I want to stop service from activity . It stops when i don't close the app . But when i close the app and run the app again service doesn't stop. </p>
  
  <p><strong>Flow :</strong> </p>
  
  <p>--> Click Switch ON <br>
  --> Show Notification / Location Listener <br>
  --> Kill App <br>
  --> Notification still remains (Service is running means) <br>
  --> Open app again and <br>
  --> Click Switch OFF <br>
  --> Service doesn't stop and notification persists <br></p>
  
  <p><strong>Service Class</strong> </p>
  
  <pre><code>public class locationService extends Service {
  
  NotificationCompat.Builder builder;
  NotificationManager notificationManager;
  
  public static final String serviceTag = "LocationServiceTag";
  
  
  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
      return mBinder;
  }
  
  @Override
  public boolean onUnbind(Intent intent) {
      return super.onUnbind(intent);
  }
  
  @Override
  public int onStartCommand(Intent intent, int flags, int startId) {
  
      SharedPreferences sharedPref = getSharedPreferences("AppPref",Context.MODE_PRIVATE);
      userCurrentRoute= sharedPref.getString("RouteNo","");
  
      mDatabase = FirebaseDatabase.getInstance().getReference();
  
      notificationManager = (NotificationManager) this.getSystemService(NOTIFICATION_SERVICE);
  
      Intent repeating_intent =new Intent(this,MainActivity.class);
  
      PendingIntent pendingIntent= PendingIntent.getActivity(this,10,repeating_intent,PendingIntent.FLAG_UPDATE_CURRENT);
  
  
       builder = new NotificationCompat.Builder(this)
              .setContentIntent(pendingIntent)
              .setSmallIcon(R.drawable.bus_small)
              .setContentTitle("BusBuzz")
              .setContentText("Sharing Location to all")
              .setAutoCancel(false)
              .setOnlyAlertOnce(true)
              .setOngoing(true)
              ;
  
      notificationManager.notify(10,builder.build());
  
      provider = new LocationGooglePlayServicesProvider();
      provider.setCheckLocationSettings(true);
  
      return START_NOT_STICKY;
  }
  
  @Override
  public void onCreate() {
      super.onCreate();
  }
  
  
  @Override
  public void onDestroy() {
      notificationManager.cancel(10);
      Toast.makeText(this, "App Closed Location Sharing Stopped", Toast.LENGTH_SHORT).show();
      SmartLocation.with(this).location().stop();
      super.onDestroy();
  }
  
  }
  </code></pre>
  
  <p><strong>Activity</strong> </p>
  
  <pre><code> if (isChecked) {
  
                  startService(new Intent(MainActivity.this,locationService.class).addCategory(locationService.serviceTag));
  
              }
              else
              {
  
  
                  stopService(new Intent(MainActivity.this,locationService.class).addCategory(locationService.serviceTag));
  
              }
  </code></pre>