this is my LocationListener... i want my location listener to get the city only once, and store it into sharedpreference, then after that i want to use that location for other purpose.All works good, but it crashes after sometime.
loclistener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Geocoder gcd = new Geocoder(getBaseContext(), Locale.getDefault());
List<Address> addresses = null;
try {
addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
} catch (IOException e) {
e.printStackTrace();
}
cityName = addresses.get(0).getLocality();
//tvLoc.append("\n" + addresses.get(0).getLocality());
tvLoc.setText(cityName);
editor.putString(CITYNAME,cityName);
// Toast.makeText(Emergencylist.this,"CityName saved :"+cityName, Toast.LENGTH_LONG).show();
editor.commit();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
};