title: My Broadcast receiver get execute even if my application is not working
body: <p>My broadcast receiver is Still getting execute even if My application is not working.</p>
  
  <p>as an example I am using android.intent.action.NEW_OUTGOING_CALL to check outgoing call and than i stop music and push notification .. 
  but even i close my app and kill all task and after if i call than i get notification of my app..
  So how do i manage to work my broadcast when i am using my app.
  I have crated Service to play music and 2 broadcast receiver file for incoming and outgoing.
  Help to solve this problem.</p>
  
  <p>Also How can i destroy my app with service running behind If user press exit button.
  **Update I made edited it and its working now fine..thank you so much you all</p>
  
  <p>here is my code </p>
  
  <pre><code>&lt;activity
          android:name=".MainActivity"
          android:label="@string/title_activity_main"
          android:launchMode="singleTask"&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="OutgoingCallInterceptor"&gt;                          
          &lt;intent-filter android:priority="1"&gt;                                  
              &lt;action android:name="android.intent.action.NEW_OUTGOING_CALL" /&gt;  
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  
      &lt;receiver android:name="IncomingCallInterceptor"&gt;                          
          &lt;intent-filter android:priority="1"&gt;                                  
              &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;  
              &lt;action android:name="android.media.AUDIO_BECOMING_NOISY" /&gt;
  
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  </code></pre>
  
  <p><strong>Update</strong>
  as you all suggest me i have made receiver into main class file and register it from there but it wont work </p>
  
  <pre><code>public class MainActivity extends Activity {
  RemoteViews layout;
  int SDK_INT;
   BroadcastReceiver br;
   @Override
      protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       IntentFilter filter = new IntentFilter("android.media.AUDIO_BECOMING_NOISY");
       this.registerReceiver(br, filter);
       setContentView(R.layout.activity_main);
           SDK_INT = android.os.Build.VERSION.SDK_INT;
          System.out.println(SDK_INT);
          Button start = (Button)findViewById(R.id.play);
          Button stop = (Button)findViewById(R.id.stop); 
          start.setOnClickListener(startListener);
          stop.setOnClickListener(stopListener);
          br = new BroadcastReceiver() {  
              @Override
              public void onReceive(Context context, Intent intent) {
                  // TODO Auto-generated method stub
                   if (intent.getAction().equals(android.media.AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
  context.stopService(new Intent(context, myPlayService.class));
                          Toast.makeText(context, "Headphones disconnected.", Toast.LENGTH_SHORT).show();
                   }
              }  }
          };
  
  @Override   
  protected void onDestroy() {
      super.onDestroy();
      unregisterReceiver(br);
  }
  </code></pre>