@@ -358,17 +358,37 @@ protected void onLocationChanged(Location location)
358358 public double getLongitude () { return m_last_location .getLongitude (); }
359359 public double getAltitude () { return m_last_location .getAltitude (); }
360360
361- //override to make sure currently known location is sent if already started by heading tracker
362- public boolean startTracking (boolean p_loosely )
363- {
364- boolean t_result ;
365- t_result = super .startTracking (p_loosely );
366- if (t_result && m_last_location != null )
367- onLocationChanged (m_last_location );
368- return t_result ;
369- }
370- }
371-
361+ //override to make sure currently known location is sent if already started by internal tracking
362+ public boolean startTracking (boolean p_loosely )
363+ {
364+ // Check if already tracking at the requested level
365+ int t_tracking_requested = p_loosely ? COARSE_TRACKING : FINE_TRACKING ;
366+
367+ if (m_tracking_requested == t_tracking_requested )
368+ return true ;
369+
370+ boolean t_result ;
371+ t_result = super .startTracking (p_loosely );
372+ if (t_result && m_last_location != null )
373+ m_engine .post (new Runnable () {
374+ public void run () {
375+ onLocationChanged (m_last_location );
376+ }
377+ });
378+ return t_result ;
379+ }
380+
381+ // override to clear cached last location if not tracking internallly
382+ public boolean stopTracking ()
383+ {
384+ boolean t_result ;
385+ t_result = super .stopTracking ();
386+ if (t_result && !isTracking ())
387+ m_last_location = null ;
388+ return t_result ;
389+ }
390+ }
391+
372392 class HeadingTracker extends Tracker implements SensorEventListener
373393 {
374394 private Sensor m_magnetometer ;
0 commit comments