We had a discussion about this sort of thing here:
http://groups.google.com/group/android-developers/browse_thread/thread/d03f0db6004345a1
but your code looks fine to me. In fact, I can't seem to reproduce.
You say it takes a few runs? I ran it a few times and didn't see the
problem. By any chance do you have a slow development machine? I'm
wondering if mine is fast enough that I don't see some kind of race
condition.

It almost looks like onFreeze isn't getting called when you have this
problem. Either that or the removeUpdates call isn't successful.

On Apr 8, 7:11 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> Would someone post code that successfully removes updates and
> unregisters receivers without ever getting the broadcast null crash?
>
> I have tried every imaginable combination of changes, including a
> boolean on variable, but with a few runs of the app, it still
> eventually gives this crash after I close, even when wiping data on
> the emulator.
>
> Here's my current relevant code:
>
>     private LocationManager locationManager;
>     private LocationIntentReceiver intentReceiver = new
> LocationIntentReceiver();
>     private static final String LOCATION_CHANGED_ACTION = new
> String("android.intent.action.LOCATION_CHANGED");
>     private IntentFilter intentFilter = new
> IntentFilter(LOCATION_CHANGED_ACTION);
>     private Intent intent = new Intent(LOCATION_CHANGED_ACTION);
>
>     @Override
>     public void onCreate(Bundle icicle) {
>         super.onCreate(icicle);
>         setContentView(R.layout.main);
>
>         locationManager =
> (LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
>         registerReceiver(intentReceiver, intentFilter);
>     }
>
>     public class LocationIntentReceiver extends IntentReceiver{
>         @Override
>         public void onReceiveIntent(Context context, Intent intent) {
>                 if (startLocation == null)
>                         return;
>
>                         //Location currentLocation = 
> (Location)intent.getExtra("location");
>                         Location currentLocation =
> locationManager.getCurrentLocation("gps");
>
>                                                 ...
>                                            }
>     }
>
>     @Override
>     public void onResume() {
>         super.onResume();
>                 List<LocationProvider> providers = 
> locationManager.getProviders();
>                 LocationProvider locationProvider = providers.get(0);
>                 locationManager.requestUpdates(locationProvider, 0, 0, 
> intent);
>     }
>
>     @Override
>     public void onFreeze(Bundle icicle) {
>         locationManager.removeUpdates(intent);
>         super.onFreeze(icicle);
>     }
>
>     @Override
>     public void onDestroy() {
>         unregisterReceiver(intentReceiver);
>         super.onDestroy();
>     }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to