LocationManager will not return destination
<p>I created this earlier on today, but it is not working. Location manager returns null, and I've even implemented the listener. Any ideas to the problems. thanks.</p>

<p>Edited:
I think this line is the problem</p>

<pre><code>Location location = locationManager.getLastKnownLocation(provider); 
</code></pre>

<p>Basically, if location is null, it will go into the else part of the if statement below it. Every time I compile the code, it will go into the else statement meaning it location is not updating.</p>

<pre><code>public class Activity1 extends Activity implements LocationListener {
/** Called when the activity is first created. */
JoshTwoActivity main;
Activity2 two;
boolean checkTick = false;
String locationplace = "";
private LocationManager locationManager;
private String provider;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


               locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, false);
    System.out.println(provider);
    System.out.println(locationManager.getProviders(criteria, false));
    System.out.println(locationManager.getProvider("network"));
    System.out.println(locationManager.getAllProviders());

    Location location = locationManager.getLastKnownLocation(provider);
    System.out.println(locationManager.isProviderEnabled(provider));

    // Initialize the location fields
    if (location != null) {
        System.out.println("Provider " + provider + " has been selected.");
        int lat = (int) (location.getLatitude());
        int lng = (int) (location.getLongitude());
        System.out.println(String.valueOf(lat));
        System.out.println(String.valueOf(lng));

    } else {
        System.out.println("Provider not available");
        System.out.println("Provider not available");
    }

}


/* Request updates at startup */
@Override
protected void onResume() {
    super.onResume();
    locationManager.requestLocationUpdates(provider, 400, 1, this);
}

/* Remove the locationlistener updates when Activity is paused */
@Override
protected void onPause() {
    super.onPause();
    locationManager.removeUpdates(this);
}

@Override
public void onLocationChanged(Location location) {
    int lat = (int) (location.getLatitude());
    int lng = (int) (location.getLongitude());
    System.out.println(String.valueOf(lat));
    System.out.println(String.valueOf(lng));
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

}

@Override
public void onProviderEnabled(String provider) {
    Toast.makeText(this, "Enabled new provider " + provider,
            Toast.LENGTH_SHORT).show();

}

@Override
public void onProviderDisabled(String provider) {
    Toast.makeText(this, "Disenabled provider " + provider,
            Toast.LENGTH_SHORT).show();
}
</code></pre>

<p>}</p>
