title: Locationmanager getLastKnownLocation always null
body: <p>i have a problem. When i test this. and i ask for the showCurrentLocation function it always returns null. It works in the emulator when i send the location after. But i need this to work on the phone, and there you can't send the location like in de DDNS window.</p>
  
  <p>Here's my code</p>
  
  <pre><code>public class LbsGeocodingActivity extends Activity {
  
  private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
  private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1; // in Milliseconds
  
  protected LocationManager locationManager;
  
  protected Button retrieveLocationButton;
  protected Button stopLocationButton;
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      retrieveLocationButton = (Button) findViewById(R.id.retrieve_location_button);
      locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
  
      locationManager.requestLocationUpdates(
              LocationManager.GPS_PROVIDER, 
              MINIMUM_TIME_BETWEEN_UPDATES, 
              MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
              new MyLocationListener()
      );
  
      retrieveLocationButton.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              showCurrentLocation();
          }
      });  
      /*stopLocationButton.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              //locationManager.removeUpdates(MyLocationListener)  ;          
          }
      }); */ 
  
  }    
  
  public String getMyPhoneNumber(){
      TelephonyManager mTelephonyMgr;
      mTelephonyMgr = (TelephonyManager)
      getSystemService(Context.TELEPHONY_SERVICE); 
      return mTelephonyMgr.getLine1Number();
  }
  
  protected void showCurrentLocation() {
  
      Criteria crit = new Criteria();
      crit.setAccuracy(Criteria.ACCURACY_FINE);
      String provider = locationManager.getBestProvider(crit, true);
      Location loc = locationManager.getLastKnownLocation(provider);
  
  
      if (loc != null) {
          String longi = "" + loc.getLongitude();
          String lat = "" + loc.getLatitude();
          String num = getMyPhoneNumber();
          String message = String.format(
                  "Current Location \n  Longitude: %1$s \n Latitude: %2$s \n %3$s ",
                  longi,
                  lat,
                  num         );
          Toast.makeText(LbsGeocodingActivity.this, message,
                  Toast.LENGTH_LONG).show();
      }
      if (loc == null)Toast.makeText(LbsGeocodingActivity.this, "Null ",
              Toast.LENGTH_LONG).show();
  }   
  
  private class MyLocationListener implements LocationListener {
  
  
  
      public void onLocationChanged(Location loc) {
          String longi = "" + loc.getLongitude();
          String lat = "" + loc.getLatitude();
          String num = getMyPhoneNumber();
          String message = String.format(
                  "New Location \n Longitude: %1$s \n Latitude: %2$s \n %3$s ",
                  longi,
                  lat,
                  num                 );
          Toast.makeText(LbsGeocodingActivity.this, message, Toast.LENGTH_LONG).show();
      }
  
      public void onStatusChanged(String s, int i, Bundle b) {
          Toast.makeText(LbsGeocodingActivity.this, "Provider status changed",
                  Toast.LENGTH_LONG).show();
      }
  
      public void onProviderDisabled(String s) {
          Toast.makeText(LbsGeocodingActivity.this,
                  "Provider disabled by the user. GPS turned off",
                  Toast.LENGTH_LONG).show();
      }
  
      public void onProviderEnabled(String s) {
          Toast.makeText(LbsGeocodingActivity.this,
                  "Provider enabled by the user. GPS turned on",
                  Toast.LENGTH_LONG).show();
      }
  
  }
  
  }
  </code></pre>
  
  <p>My permissions are:  FINE_LOCATION COURSE_LOCATION.</p>
  
  <p>I really just want it that it tracks the users location, even on the background.. </p>