@@ -37,6 +37,7 @@ public class AnimatedDashLineActivity extends AppCompatActivity implements OnMap
3737 private MapboxMap mapboxMap ;
3838 private Handler handler ;
3939 private String tag = "AnimatedDashLine" ;
40+ private RefreshDashAndGapRunnable refreshDashAndGapRunnable ;
4041
4142 @ Override
4243 protected void onCreate (Bundle savedInstanceState ) {
@@ -49,6 +50,7 @@ protected void onCreate(Bundle savedInstanceState) {
4950 // This contains the MapView in XML and needs to be called after the access token is configured.
5051 setContentView (R .layout .activity_animated_dash_line );
5152
53+ handler = new Handler ();
5254 mapView = findViewById (R .id .mapView );
5355 mapView .onCreate (savedInstanceState );
5456 mapView .getMapAsync (this );
@@ -76,7 +78,7 @@ private void initBikePathLayer() {
7678 );
7779 mapboxMap .addLayer (animatedDashBikeLineLayer );
7880 Log .d (tag , "initBikePathLayer: here" );
79- Runnable runnable = new RefreshDashAndGapRunnable (this .mapboxMap , new Handler () );
81+ Runnable runnable = new RefreshDashAndGapRunnable (this .mapboxMap , handler );
8082 Log .d (tag , "initBikePathLayer: runnable made" );
8183 handler .postDelayed (runnable , 25 );
8284 Log .d (tag , "initBikePathLayer: postDelayed" );
@@ -113,7 +115,6 @@ private static class RefreshDashAndGapRunnable implements Runnable {
113115 this .handler = handler ;
114116 Log .d (TAG , "RefreshDashAndGapRunnable: finished" );
115117
116- mapboxMap .getProjection ().getProjectedMetersForLatLng ()
117118 }
118119
119120 @ Override
@@ -180,6 +181,9 @@ public void onLowMemory() {
180181 protected void onDestroy () {
181182 super .onDestroy ();
182183 mapView .onDestroy ();
184+ handler .removeCallbacks (refreshDashAndGapRunnable );
185+ refreshDashAndGapRunnable = null ;
186+ handler = null ;
183187 }
184188
185189 @ Override
0 commit comments