LocationListener with Geocoded Toast not stopping once activity leaves “OnCreate”

I have a simple locationListener that is using GPS only to start. Inside OnLocationChanged I do a geocode lookup and display a Toast message. The problem is once the activity is no longer in front the gps is still receiving updates and processing the Toasto. I have RemoveUpdates in onStart, onPause, onDestroy and onStop.

Any idea why I can't get this service to stop?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    mapView = (MapView) findViewById(R.id.mapView);
    mc = mapView.getController();

    locationListener = new GPSLocationListener(); 
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);           
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);    

...
...       

public void onStart(Bundle savedInstanceState) {
    locationManager.removeUpdates(locationListener);
    locationManager=null;
}

public void onPause(Bundle savedInstanceState) {
    locationManager.removeUpdates(locationListener);
    locationManager=null;
}

public void onDestroy(Bundle savedInstanceState) {
    locationManager.removeUpdates(locationListener);
    locationManager=null;
}

public void onStop(Bundle savedInstanceState) {
    locationManager.removeUpdates(locationListener);
    locationManager=null;
}

class GPSLocationListener implements LocationListener {     
    @Override
    public void onLocationChanged(Location location) {
        if (location != null) {

          current_heading=location.getBearing();
          String current_bearing = headingToString2(location.getBearing());

          point = new GeoPoint(
              (int) (location.getLatitude() * 1E6), 
              (int) (location.getLongitude() * 1E6));

          // add marker
          MapOverlay mapOverlay = new MapOverlay();
          mapOverlay.setPointToDraw(point);
          List<Overlay> listOfOverlays = mapView.getOverlays();
          listOfOverlays.clear();
          listOfOverlays.add(mapOverlay);

          mapView.setStreetView(showStreet);
          // enable to show Satellite view
          mapView.setSatellite(showSatellite);        
          // enable to show Traffic on map
          mapView.setTraffic(showTraffic);        
          mapView.setBuiltInZoomControls(true);

          mc.animateTo(point);
          mc.setZoom(16);

          address = ConvertPointToLocation(point);
          Toast.makeText(getBaseContext(), address, Toast.LENGTH_LONG).show();
          Toast.makeText(getBaseContext(), address, Toast.LENGTH_LONG).cancel();
          }     
    } 

Here is the LogCat when attempting to go home

12-28 16:41:51.402: ERROR/LocationMasfClient(577): reverseGeocode(): GLS failed with status 20
12-28 16:41:51.423: INFO/NotificationService(577): enqueueToast pkg=com.kuli.example.android511 callback=android.app.ITransientNotification$Stub$Proxy@4375d1f0 duration=1
12-28 16:41:53.272: DEBUG/LocationMasfClient(577): getAddressFromProtoBuf(): Ignore feature 0,Lyndon Station
12-28 16:41:53.282: INFO/NotificationService(577): enqueueToast pkg=com.kuli.example.android511 callback=android.app.ITransientNotification$Stub$Proxy@43711b70 duration=1
12-28 16:41:55.533: DEBUG/dalvikvm(633): GC freed 715 objects / 92504 bytes in 324ms
12-28 16:41:57.883: INFO/ActivityManager(577): Starting activity: Intent { action=android.intent.action.MAIN categories={android.intent.category.HOME} flags=0x10200000 comp={com.android.launcher/com.android.launcher.Launcher} }
12-28 16:41:57.932: DEBUG/LocationManager(1191): removeUpdates: listener = com.kuli.example.android511.android511$GPSLocationListener@43762f40
12-28 16:41:57.952: DEBUG/AndroidRuntime(1191): Shutting down VM
12-28 16:41:57.952: WARN/dalvikvm(1191): threadid=3: thread exiting with uncaught exception (group=0x4000fe70)
12-28 16:41:57.966: ERROR/AndroidRuntime(1191): Uncaught handler: thread main exiting due to uncaught exception
12-28 16:41:57.972: ERROR/AndroidRuntime(1191): android.app.SuperNotCalledException: Activity {com.kuli.example.android511/com.kuli.example.android511.android511} did not call through to super.onPause()
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2830)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2797)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2780)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at android.app.ActivityThread.access$2000(ActivityThread.java:112)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1699)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at android.os.Handler.dispatchMessage(Handler.java:99)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at android.os.Looper.loop(Looper.java:123)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at android.app.ActivityThread.main(ActivityThread.java:3948)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at java.lang.reflect.Method.invokeNative(Native Method)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at java.lang.reflect.Method.invoke(Method.java:521)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):     at dalvik.system.NativeStart.main(Native Method)
12-28 16:41:57.992: INFO/Process(577): Sending signal. PID: 1191 SIG: 3
12-28 16:41:57.992: INFO/dalvikvm(1191): threadid=7: reacting to signal 3
12-28 16:41:58.133: INFO/dalvikvm(1191): Wrote stack trace to '/data/anr/traces.txt'
12-28 16:41:58.442: WARN/ActivityManager(577): Activity pause timeout for HistoryRecord{437b5170 {com.kuli.example.android511/com.kuli.example.android511.android511}}
12-28 16:43:08.393: DEBUG/dalvikvm(631): GC freed 9811 objects / 553776 bytes in 104ms

Answers


You're not overriding any methods.

public void onStart(Bundle savedInstanceState) {
    locationManager.removeUpdates(locationListener);
    locationManager=null;
}

public void onPause(Bundle savedInstanceState) {
    locationManager.removeUpdates(locationListener);
    locationManager=null;
}

public void onDestroy(Bundle savedInstanceState) {
    locationManager.removeUpdates(locationListener);
    locationManager=null;
}

public void onStop(Bundle savedInstanceState) {
    locationManager.removeUpdates(locationListener);
    locationManager=null;
}

Those aren't the method signatures for those methods. It should be

@Override
protected void onStart(){

}

etc

You should get used to adding the @Override annotation to methods that you're overriding


Need Your Help

How do I convert a basicHttpBinding to a customBinding

wcf

I've been working on converting a basicHttpBinding to a customBinding to get my client working on a web farm. I've been fumbling translating the following security section.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.