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

Reply via email to