title: Pass message or data from looper to main thread
body: <p>My app uses a broadcastreciever that spawns two threads which contain Loopers ReceiverAccLooper and GetListingsLooper. These two loopers then call some other tasks to run that then return a result back to the Looper. I cannot figure out how to get the result from the loopers back to the main task to further process the data. </p>
  
  <p>I've tried callbacks and handlers, the only success I've had is using pool.awaitTermination but that seems sloppy. My understanding is the best way to do this is with a handler but I cannot figure out how to get a handler to send from the looper to the main task. Any insight on the best way to do this would be very helpful.</p>
  
  <p>Mainthread...</p>
  
  <pre><code>public void onReceive(Context context, Intent intent) {
      Log.d("Plog", "Reciever accounts received alarm");
  
      DatabaseHandler db = new DatabaseHandler(context);
      List&lt;Contact&gt; contacts = db.getAllContacts();
      Log.d(Plog, "Contacts" + contacts);
      for (Contact cn : contacts) {
          username = cn.getName();
          password = cn.getPassword();
          acb = cn.getBalance();
          strategykey = Integer.parseInt(cn.getStrategy());
          maxamountperautoloan = cn.getMaxperloan();
          int n = 2;
          // Build a fixed number of thread pool
          ExecutorService pool = Executors.newFixedThreadPool(n);
  
          pool.submit(new ReceiverAccLooper(username, password, acb, maxamountperautoloan, strategykey));
  
          pool.submit(new GetListingsLooper(username, password, strategykey));
  
          pool.shutdown();
  
          //This is where I've been trying to place a handler to get output from the two loopers above
  
  }
  </code></pre>
  
  <p>One of the Loopers....</p>
  
  <pre><code>public class ReceiverAccLooper implements Runnable{
  private String username;
  private String password;
  private String maxamountperloan;
  private String acb;
  private Integer strategy;
  List&lt;Map&lt;String, String&gt;&gt; result;
  
  public ReceiverAccLooper(String _username, String _password, String _acb, String _maxamountperloan, Integer _strategy){
      this.username = _username;
      this.password = _password;
      this.maxamountperloan = _maxamountperloan;
      this.strategy = _strategy;
      this.acb = _acb;
  }
  
  @Override
  public void run() {
      Looper.prepare();
      Log.d("Plog", "In Looper " + username + " " + password + " " + maxamountperloan + " " + strategy + " " + acb);
  
      GetLoansReturn glr = new GetLoansReturn();
      glr.GetLoansRunner(username, password, acb, maxamountperloan);
      result = glr.planetsList;
      Log.d("Plog", username + " Looper Result Owned Listings " + result);
  
      Object msg = result;
      Message sent = (Message) msg;
  
      //I've would like to send the message from here....
  
      Looper myLooper = Looper.myLooper();
      Looper.loop();
      myLooper.quit();
  
  }   
  </code></pre>
  
  <p>}</p>