title: Broadcast Receiver class and registerReceiver method
body: <p>Hi i am trying to understand Broadcast Receiver , i went through many sample codes , but still have some doubts. I wanted to know when we have to extend the Broadcast Receiver class and when should we use <code>registerReceiver()</code> method and when should we create object for BroadcastReceiver. In some programs i came across <code>registerReceiver</code> methods being used but without extending the Broadcast Receiver class. I also wanted to know how the <code>onReceive</code> method gets called.</p>
  
  <p>Which approach should be used when? </p>
  
  <p>here is the <strong>registerReceiver</strong> method:</p>
  
  <pre><code>registerReceiver(new BroadcastReceiver() {
  
              @Override
              public void onReceive(Context context, Intent intent) {
                  switch (getResultCode()) {
                  ........
                  }
  
              }
  
          }, new IntentFilter(SENT));
  </code></pre>
  
  <p>Object being created for <code>BroadcastReceiver</code>:</p>
  
  <pre><code>private BroadcastReceiver intentReceiver = new BroadcastReceiver() {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          .................
      }
  
  };
  </code></pre>