title: Broadcastreceiver creating multiple instances of TelephonyManager
body: <p>This is my BroadcastReceiver</p>
  <pre><code>public class PlayAudio extends BroadcastReceiver {
   
      @Override
      public void onReceive(Context context, Intent intent) {
  
          TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
          tm.listen(new CustomPhoneStateListener(context), PhoneStateListener.LISTEN_CALL_STATE);
      }
  }
  </code></pre>
  <p>This is my Custom PhoneStateListener Class</p>
  <pre><code>public class CustomPhoneStateListener extends PhoneStateListener {
  
      Context context; 
      
      public CustomPhoneStateListener(Context context) {
          super();
          this.context = context;
      }
      
      @Override
      public void onCallStateChanged(int state, String incomingNumber) {
          super.onCallStateChanged(state, incomingNumber);
  
          switch (state) {
          case TelephonyManager.CALL_STATE_IDLE:
              Log.d(&quot;PHONEA&quot;, &quot;IDLE&quot;);
              break;
          case TelephonyManager.CALL_STATE_OFFHOOK:
             Log.d(&quot;PHONEA&quot;, &quot;OFFHOOK&quot;);
              break;
          case TelephonyManager.CALL_STATE_RINGING:
              Log.d(&quot;PHONEA&quot;, &quot;RINGING&quot;);
              Intent intent = new Intent(this.context, AudioService.class);
              context.startService(intent);
              break;
          default:
              break;
          }
      }
  }
  </code></pre>
  <p>and this is my service</p>
  <pre><code>public class AudioService extends Service{
      private static final String TAG = &quot;PHONEA&quot;;
      MediaPlayer player;
      
      @Override
      public IBinder onBind(Intent intent) {
          return null;
      }
      
      @Override
      public void onCreate() {
          Log.d(TAG, &quot;onCreate -&gt; TODO&quot;);
          }
  }
  </code></pre>
  <p>My question is that every time I receive data in Broadcast receiver I create a new instance of the <code>TelephonyManager</code>. So when I view the logcat the first time I get &quot;RINGING&quot;, the second time &quot;RINGING&quot; &quot;RINGING&quot; and so on. When should I create my <code>telephonylistener</code> in order to have only one instance?</p>
  <p>Regards,
  Nicos</p>