My app is heavily run off GeoCoordinates, and I have it so when users Post a Book it records the users geo coordinate like so:
PostBookButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
locationListener = new ObtainLocation();
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener);
}
});
public class ObtainLocation implements LocationListener{
@Override
public void onLocationChanged(Location loc) {
if (loc != null)
{
Latitude = loc.getLatitude();
Longitude = loc.getLongitude();
ParseGeoPoint itemLoc = new ParseGeoPoint(Latitude,Longitude);
book.setGeoLocation(itemLoc);
book.saveInBackground(new SaveCallback()
{
@Override
public void done(ParseException e) {
if (e == null)
{
finish();
}
else
{
}
}
});
}
}
else
{
}
locationManager.removeUpdates(locationListener);
}
But problem is app will crash if the activity is ran with no network connection, seeing how it won't be able to obtain the geopoint coordinates.
How would I just make it so if the app fails on obtaining coordinates, instead of crashing maybe alert the user they cannot view books in their area due to no way to obtain their current location.