Unregister Broadcast Receiver - Android
<p>I have a <code>BroadcastReceiver</code> for one time use. </p>

<p>I'm registering it in an Activity. I can't put the <code>unregisterReceiver()</code> in <code>onPause</code> because it has to stay running even when the activity is paused or destroyed. </p>

<p>I want the BroadcastReceiver to unregister itself when it is done, something like this:</p>

<pre><code>public class SmsReceiver extends BroadcastReceiver {

    public void onReceive(Context context, Intent intent) {
           // do some code..
           context.unregisterReceiver(this)
        }
}
</code></pre>

<p>But it causes an Exception: <code>Receiver not registered.</code> </p>
