Makes sense! Don't know why that never even crossed my mind... thank you! On Mar 2, 2011 4:43 PM, "Kostya Vasilyev" <[email protected]> wrote: > Rich, > > Without checking / setting those receivers for null, your code could be > trying to unregister the same receiver object multiple times. Clearly, > that's not a good thing to be doing. > > -- Kostya > > 03.03.2011 0:10, rich friedel пишет: >> I ran into an issue today where in my service I am calling >> onLowMemory() and unregistering my receivers within the method before >> the system kills the service. >> >> I've (hopefully) fixed this using some suggestions I found when other >> devs had the issue with ViewFlipper... >> >> The code before looked like: >> @Override >> public void onLowMemory() { >> super.onLowMemory(); >> >> // Unregister BroadcastReceiver >> this.unregisterReceiver(this.smsReceiver); >> this.unregisterReceiver(this.sentReceiver); >> this.unregisterReceiver(this.deliveredReceiver); >> } >> >> The fix looks like: >> @Override >> public void onLowMemory() { >> super.onLowMemory(); >> >> // Unregister BroadcastReceiver >> if( this.smsReceiver != null ) { >> this.unregisterReceiver(this.smsReceiver); >> this.smsReceiver = null; >> } >> >> if( this.sentReceiver != null ) { >> this.unregisterReceiver(this.sentReceiver); >> this.sentReceiver = null; >> } >> >> if( this.deliveredReceiver != null ) { >> this.unregisterReceiver(this.deliveredReceiver); >> this.deliveredReceiver = null; >> } >> } >> >> My question is, if unregisterReceiver() simply unregisters any >> receivers passed to it; why does checking for a not null situation and >> setting the receiver to null after unregistering the receiver make it >> so it doesn't throw an illegalArguementException? >> -- >> 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] >> For more options, visit this group at >> http://groups.google.com/group/android-developers?hl=en > > > -- > Kostya Vasilyev -- http://kmansoft.wordpress.com > > -- > 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] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en
-- 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] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

