title: passing data back to activity from service
body: <p>In order to pass data back to activity from service, I came to know about <strong>ResultReceiver</strong>, <strong>broadcast/local broadcasts</strong> and <strong>binded service</strong>. However I am confused about this approach: If we simply call activity static public funcion to pass something back, what are the pros and cons of this approach. Say I have activity:</p>
  
  <pre><code>public interface ListenerInterface {
  
      void DataExchange(String data);
  
  
  }
  public class MainActivity extends Activity implements ListenerInterface{
  
      private static MainActivity instance;
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          instance=this;
  
          Intent i=new Intent();
          i.setClass(this, MyService.class);
          startService(i);
      }
  
      public static MainActivity getInstance(){
          if(instance!=null)
              return instance;
  
          return null;
      }
  
      @Override
  public void DataExchange(String data) {
      // TODO Auto-generated method stub
      Log.d("sohail","data received="+data);
  }
  
  }
  </code></pre>
  
  <p>and an IntentService:</p>
  
  <pre><code>public class MyService extends IntentService{
  
      MainActivity obj;
      public MyService() {
          super("MyService");
          // TODO Auto-generated constructor stub
      }
  
      @Override
      protected void onHandleIntent(Intent arg0) {
          // TODO Auto-generated method stub
  
          MainActivity.getInstance().DataExchange("Service Data");
      }
  
  }
  </code></pre>