title: Start and Stop broadcastReceiver from activity
body: <p>I created a broadcastReceiver </p>
  
  <p>in manifest</p>
  
  <pre><code>&lt;receiver android:name="SMSMonitor"&gt;
              &lt;intent-filter android:priority="100"&gt;
                  &lt;action android:name="android.provider.Telephony.SMS_RECEIVED"/&gt;
              &lt;/intent-filter&gt;
          &lt;/receiver&gt;
  </code></pre>
  
  <p>class:</p>
  
  <pre><code>public class SMSMonitor extends BroadcastReceiver {
      private static final String ACTION = "android.provider.Telephony.SMS_RECEIVED";
  
      @Override
      public void onReceive(Context context, Intent intent) {
          if (intent != null &amp;&amp; intent.getAction() != null &amp;&amp; ACTION.compareToIgnoreCase(intent.getAction()) == 0) {
              Object[] pduArray = (Object[]) intent.getExtras().get("pdus");
              SmsMessage[] messages = new SmsMessage[pduArray.length];
              for (int i = 0; i &lt; pduArray.length; i++) {
                  messages[i] = SmsMessage.createFromPdu((byte[]) pduArray[i]);
              }
              StringBuilder bodyText = new StringBuilder();
              for (SmsMessage message : messages) {
                  bodyText.append(message.getMessageBody());
              }
              String body = bodyText.toString();
              Observer.getInstance().send(new SmsEvent(body));
              abortBroadcast();
          }
      }
  </code></pre>
  
  <p>When started my app receiver starts to wortk. But I have 2 buttons in activity "start" and "stop". I want to start receiver when i press "start" button and stop when press "stop" button. How can i do it? </p>