title: Location Listener - Not starting from a Service but it works from an Activity
body: <p>I'm trying to call a LocationListener class from a Service, but It seems that the listener doesn't start.
  It worked well when I called it from an Activity.
  When I tryed the same (only deleting "this" parameter) it doesn't work.</p>
  
  <p>It seems to be something wrong with the context parameter but I don't know how to solve it.</p>
  
  <p>Calling from Activity (working):</p>
  
  <pre><code>LocationTest2 locationListener = new LocationTest2(getApplicationContext());
  LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
  locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
  </code></pre>
  
  <p>Calling from Service (Not working):</p>
  
  <pre><code>LocationTest2 locationListener = new LocationTest2(getApplicationContext());
  LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
  </code></pre>
  
  <p>Class: LocationTest2:</p>
  
  <pre><code>public class LocationTest2 extends Thread implements LocationListener {
  private String TAG = "LocationTest2";
  private Context context;
  private boolean isOnline = false;
  
  private LocationManager locationManager;
  
  public LocationTest2(Context context) {
      LogSys.e(TAG, "Serviço criado!");
      this.context = context;
  }
  
  
  public void startListening() {
      isOnline = true;
      LogSys.e(TAG, "Ligando serviço");
      Toast.makeText(context, "Ligando serviço!", Toast.LENGTH_SHORT).show();
      locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
      locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
  }
  
  public void stopListening() {
      if(locationManager != null)
      {
          Toast.makeText(context, "Desligando serviço!", Toast.LENGTH_SHORT).show();
          locationManager.removeUpdates(this);
      }
      isOnline = false;
  }
  
  public boolean isOnline()
  {
      return isOnline;
  
  }
  //=================================
  
  @Override
  public void onLocationChanged(Location location) {
      String locationStr = "LOCATION WORKED 33!!! " + location.getLatitude() + " | " + location.getLongitude();
      LogSys.e(TAG, locationStr);
      Toast.makeText(context, locationStr, Toast.LENGTH_SHORT).show();
  
      setLocationToFirebase(location);
  }
  
  public void setLocationToFirebase(Location location)
  {
      String tbl_cliente = GlobalVars.SQL_TABELA_CLIENTE_DEVICE_NAME;
      String tbl_dispositivo = GlobalVars.SQL_TABELA_DISPOSITIVO_NAME;
      String tbl_coordinates = GlobalVars.SQL_TABELA_COORDINATES_NAME;
  
      DatabaseReference databaseReference;
      FirebaseDatabase firebaseDatabase;
  
      firebaseDatabase = FirebaseDatabase.getInstance();
      try {
          firebaseDatabase.setPersistenceEnabled(true);
      }catch(DatabaseException e){
          LogSys.e(TAG, "DatabaseException: " + e.getMessage());
      }
      databaseReference = firebaseDatabase.getReference();
  
      Cliente clienteSQLite = Cliente.getClienteSQLite(context);
      Dispositivo dispositivoSQLite = Dispositivo.getDispositivoSQLite(context);
  
      DatabaseReference dbRef = databaseReference.child(tbl_cliente)
              .child(clienteSQLite.getId())
              .child(tbl_dispositivo)
              .child(dispositivoSQLite.getId())
              .child(tbl_coordinates).push();
      String key = dbRef.getKey();
  
      Coordenadas coords = new Coordenadas();
      coords.setId(key);
      coords.setLatitude(location.getLatitude());
      coords.setLongitude(location.getLongitude());
      coords.setData(DataHoraAtual.getData());
      coords.setHora(DataHoraAtual.getHora());
  
      dbRef.setValue(coords);
  }
  
  @Override
  public void onStatusChanged(String s, int i, Bundle bundle) {
  
  }
  
  @Override
  public void onProviderEnabled(String s) {
  
  }
  
  @Override
  public void onProviderDisabled(String s) {
  
  }
  }
  </code></pre>
  
  <p>Does someone has any idea? Thanks.</p>