title: How to unregister BroadcastReceiver
body: <p>My app uses a BroadcastReceiver to get sms in this way:</p>
  
  <p><strong>SmsBR.java</strong></p>
  
  <pre><code>public class SmsBR extends BroadcastReceiver {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          Bundle bundle = intent.getExtras();
          if (bundle != null) {
              Object[] pdus = (Object[])bundle.get("pdus");
              final SmsMessage[] messages = new SmsMessage[pdus.length];
  
              for (int i = 0; i &lt; pdus.length; i++) {
                  messages[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
              }
              if (messages.length &gt; 0)
                  //doSomething();
              }
          }
      }
  }
  </code></pre>
  
  <p><strong>Manifest.xml</strong></p>
  
  <p>
  
  
  <pre><code>&lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
      &lt;activity android:name=".Activity" android:label="@string/app_name"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt; 
      &lt;/activity&gt;
  
      &lt;receiver android:name=".SmsBR"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.provider.Telephony.SMS_RECEIVED"&gt;&lt;/action&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  &lt;/application&gt;    
  </code></pre>
  
  <p></p>
  
  <p>In this way SmsBR is always ON. I want to register it when a service starts (<code>onCreate()</code>) and unregister it when the service is destroyed (<code>onDestroy()</code>). How can I do this?</p>