title: Android Best-Way to communicate with a Foreground Service
body: <p>I am bit new to android. I would like to know how to communicate with a foreground started service.</p>
  
  <p>So, I got a Foreground service with a notification. 
  This notification has a (X) button to stop the service.</p>
  
  <p>The service got a Static broadcastreceiver.</p>
  
  <pre><code>public static class NotificationStopButtonHandler extends BroadcastReceiver {
          @Override
          public void onReceive(Context context, Intent intent) {
              Toast.makeText(context,"Close Clicked",Toast.LENGTH_SHORT).show();
              Log.i(LOG_TAG, "In Closed");
  
              // imposible to do context.stopForground(true) or
              // to call any other private coded by me
          }
  }
  </code></pre>
  
  <p>So my question is : 
  Is BroadcastReceiver is the best way ? 
  If it is : How I can communicate with the service to call stopForeground in the broadcastReceiver ? </p>
  
  <p>Thanks in advance for your responses.</p>
  
  <p><a href="https://stackoverflow.com/questions/38726398/why-cant-we-call-stopforeground-method-in-the-broadcast-receiver-class/40310473#40310473">Same question like mien...</a> But I would like to know which are the other solution than broadcastReceiver. thx</p>