title: Passing data from activity to service through interface
body: <p>I am trying to pass data from an Android Activity to a Service. I am attempting to do so by calling a method within another class which contains an interface,this interface is implemented by the Service.</p>
  
  <p>MQTTNotifier(Activity) >> MQTTServiceDelegate(Middle Man, Has Interface) >> MQTTService (Implements Interface)</p>
  
  <p><strong>Is this possible? I cannot seem to get the String topic any further than the MQTTServiceDelegate subscribeToTopic() method, I would like to forward it to the Service now.</strong></p>
  
  <p><strong>MQTTNotifier Activity</strong></p>
  
  <p>Here is the call I am making to a method inside MQTTServiceDelegate, and I am passing it a String topicName.</p>
  
  <pre><code>MQTTServiceDelegate.subscribeToTopic(topicName);
  </code></pre>
  
  <p><strong>MQTTServiceDelegate ( Middle Man )</strong></p>
  
  <p>Here is the interface</p>
  
  <pre><code>public interface SubscribeHandler {
      public void handleSubscribe(String topic);
  }
  </code></pre>
  
  <p>Here I am attempting to take the String topic, and pass it to the interface, which I would like the Service to receive and do something with.</p>
  
  <pre><code>  public static void subscribeToTopic(String topic) {
    SubscribeHandler subscribeHandler = new SubscribeHandler() {
  
      @Override
      public void handleSubscribe(String topic) {
        // TODO Auto-generated method stub
  
        // WHAT DO I DO HERE?
  
  
      }
    }; 
  }
  </code></pre>
  
  <p><strong>MQTTService</strong></p>
  
  <p>This is the interface method implementation inside the Service</p>
  
  <pre><code>  @Override
    public void handleSubscribe(String topic) {
      // TODO Auto-generated method stub
      if (isOnline()) {
  
        if (connectToBroker()) {
  
          Log.e("SUBSCRIBE TO ANOTHER TOPIC", "SUBSCRIBE TO ANOTHER TOPIC");
          subscribeToTopic(topic);
        }
      }
  
    }
  </code></pre>