title: How can I use getSystemService in a non-activity class (LocationManager)?
body: <p>I'm having trouble offloading tasks from the main Activities OnCreate method onto another class to do the heavy lifting.</p>
  
  <p>When I try to call getSystemService from the non-Activity class an exception is thrown.</p>
  
  <p>Any help would be greatly appreciated :)</p>
  
  <p>lmt.java:</p>
  
  <pre><code>package com.atClass.lmt;
  import android.app.Activity;
  import android.os.Bundle;
  import android.widget.TextView;
  import android.location.Location;
  
  public class lmt extends Activity {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.main);
  
          fyl lfyl = new fyl();
          Location location = lfyl.getLocation();
          String latLongString = lfyl.updateWithNewLocation(location);
  
          TextView myLocationText = (TextView)findViewById(R.id.myLocationText);
          myLocationText.setText("Your current position is:\n" + latLongString);
      }
  }
  </code></pre>
  
  <p>fyl.java</p>
  
  <pre><code>package com.atClass.lmt;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.location.Location;
  import android.location.LocationManager;
  import android.os.Bundle;
  import android.widget.TextView;
  import android.content.Context;
  
  public class fyl {
      public Location getLocation(){
          LocationManager locationManager;
          String context = Context.LOCATION_SERVICE;
          locationManager = (LocationManager)getSystemService(context);
  
          String provider = LocationManager.GPS_PROVIDER;
          Location location = locationManager.getLastKnownLocation(provider);
  
          return location;
      }
  
      public String updateWithNewLocation(Location location) {
          String latLongString;
  
          if (location != null){
              double lat = location.getLatitude();
              double lng = location.getLongitude();
              latLongString = "Lat:" + lat + "\nLong:" + lng;
          }else{
              latLongString = "No Location";
          }
  
          return latLongString;
      }
  }
  </code></pre>