Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think your problem is that your location updates listener is updating the location variable inside your UserLocation class, however the variable you are checking is the one you get back from the method gpsLocation, which is null.</p> <p>What you are doing is you are signing up for location updates and immediately returning the value of null and checking it over and over again, while your real location is being updated in another place.</p> <p>All this is also assuming that you have declares the proper permission in your manifest file.</p> <p>Try this:</p> <pre><code>Location location; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); gpsLocation(this); while(location == null) continue; Log.w("GPS LOCATION", "LOCATION FOUND"); } public static void gpsLocation(FragmentActivity context) { LocationManager provider = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); UserLocator locator = new UserLocator(); provider.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locator); } class UserLocator implements LocationListener { public void onLocationChanged(Location loc) { if(loc != null) location = loc; } public void onProviderDisabled(String provider) {} public void onProviderEnabled(String provider) {} public void onStatusChanged(String provider, int status, Bundle extras) {} } </code></pre> <p>With this implementation, both the listener and the while loop address the same instance of Location, so once this changes from null you will get the log message.</p> <p>I would however strongly discourage putting such a while(true) loop in your onCreate method, you will be blocking the main thread, and this is generally a bad thing to do.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload