Make SharePreferenceListener instance variables so they do not get

garbage collected early.
This commit is contained in:
Jimmy Shih
2012-09-11 14:56:17 -07:00
parent 32da1cd84d
commit 0ef7713433
4 changed files with 92 additions and 76 deletions
@@ -56,7 +56,17 @@ import java.util.concurrent.BlockingQueue;
*
* @author Leif Hendrik Wilden
*/
public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListener {
public class MapOverlay extends Overlay {
private final OnSharedPreferenceChangeListener
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (PreferencesUtils.getKey(context, R.string.track_color_mode_key).equals(key)) {
trackPathPainter = TrackPathPainterFactory.getTrackPathPainter(context);
}
}
};
private final Context context;
private final List<Waypoint> waypoints;
@@ -181,7 +191,7 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe
trackPathPainter = TrackPathPainterFactory.getTrackPathPainter(context);
context.getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE)
.registerOnSharedPreferenceChangeListener(this);
.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
}
/**
@@ -366,13 +376,6 @@ public class MapOverlay extends Overlay implements OnSharedPreferenceChangeListe
return super.onTap(geoPoint, mapView);
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (PreferencesUtils.getKey(context, R.string.track_color_mode_key).equals(key)) {
trackPathPainter = TrackPathPainterFactory.getTrackPathPainter(context);
}
}
/**
* Gets the points.
*/