title: Android [LocationManager] requestLocationUpdates(), java.lang.RuntimeException
body: <p>I am getting this error when requestion for location updates inside <code>service</code>. Location permission is granted, <code>LocationManager</code> is not null, <code>Provider</code> is not null.</p>
  
  <pre><code>LocationManager: [LocationManager] requestLocationUpdates(), 
      java.lang.RuntimeException
          at android.location.LocationManager.requestLocationUpdates(LocationManager.java:1013)
          at android.location.LocationManager.requestLocationUpdates(LocationManager.java:595)
          at com.trackinglibrary.service.DataService.createAndRequestLocationUpdates(DataService.java:759)
          at com.trackinglibrary.service.DataService.onStartCommand(DataService.java:252)
          at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3694)
          at android.app.ActivityThread.access$1600(ActivityThread.java:202)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1696)
          at android.os.Handler.dispatchMessage(Handler.java:107)
          at android.os.Looper.loop(Looper.java:198)
          at android.app.ActivityThread.main(ActivityThread.java:6729)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
  </code></pre>
  
  <p>Location code that I am calling inside  <code>onStartCommand()</code>:</p>
  
  <pre><code>@SuppressLint("MissingPermission")
      private void createAndRequestLocationUpdates() {
          try {
  
              if (!TrackThatUtils.isLocationEnabled(getApplicationContext())) {
                  Log.e(TAG, "Location is disable.");
                  return;
              }
  
              if (locationManager == null) {
                  locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
  
                  addProximityAlert();
              }
  
              if (locationManager == null || !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
                  Log.e(TAG, "Location provider is disable.");
                  return;
              }
  
              // getting GPS status
              boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  
              Log.e(TAG, "Location provider is: " + isGPSEnabled);
  
              if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp;
                      ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                  // TODO: Consider calling
                  //    ActivityCompat#requestPermissions
                  // here to request the missing permissions, and then overriding
                  //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                  //                                          int[] grantResults)
                  // to handle the case where the user grants the permission. See the documentation
                  // for ActivityCompat#requestPermissions for more details.
  
                  Log.e(TAG, "== Error On onConnected() Permission not granted");
                  //Permission not granted by user so cancel the further execution.
                  return;
              }
  
  
              Criteria criteria = new Criteria();
              criteria.setAccuracy(Criteria.ACCURACY_FINE);
              criteria.setPowerRequirement(Criteria.NO_REQUIREMENT);
              criteria.setAltitudeRequired(false);
              criteria.setSpeedRequired(true);
              //setCostAllowed(true): This flag enables LocationManager to exchange “data packet” with
              // 3G/4G network base stations in order to get better location
              criteria.setCostAllowed(true);
              criteria.setBearingRequired(false);
  
              //API level 9 and up
              criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
              criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH);
  
              String provider = locationManager.getBestProvider(criteria, true);
  
  //          locationManager.requestLocationUpdates(gpsFreqInMillis, gpsFreqInDistance, criteria, locationListener, null);
  
              locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                      0, this);
              Log.i(TAG, "request for location updates..");
          } catch (SecurityException | IllegalArgumentException e) {
              Log.e(TAG, "Exception inside createAndRequestLocationUpdates(): " + e);
          }
      }
  </code></pre>