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
-~----------~----~----~----~------~----~------~--~---