title: Where to Unregister a Broadcast reciever in custom control
body: <p>I have a custom music player control, that starts a Service on click of the play button and registers a BroadcastReceiver.
  The service plays the music and broadcasts the music details, which i use in the music player control to update the UI.</p>
  
  <pre><code>public class MusicPlayer extends ViewFlipper implements OnClickListener
  </code></pre>
  
  <p>{
      private BroadcastReceiver broadcastReceiver;</p>
  
  <pre><code>MusicPlayer(Context context, AttributeSet attrs)
  {
      //inflate the layout
  }
  public void onClick(View v) 
  {
      if(v.getId() == R.id.musicplayerbtn)
      {
          // DO some work
          // register receiver
          broadcastReceiver = new BroadcastReceiver() 
          {
              @Override
              public void onReceive(Context context, Intent serviceIntent) 
              {
                  updatePlayer(serviceIntent);
              }
          };
          // Register receiver
          getContext().registerReceiver(broadcastReceiver, new IntentFilter(MusicService.BROADCAST));
  
          //Start service
      }
  }
  }
  </code></pre>
  
  <p>My app has multiple screens and I just plugin this control on these screens. When navigating from one Activity to another, the music player on the first Activity's layout needs to understand it is no longer visible and unregister the BroadcastReceiver.</p>
  
  <p>Where/how do I unregister the BroadcastReceiver in the custom control?I would prefer not to unregister it in Activity onPause() method.</p>