title: Implementing Broadcast receivers within asynctask
body: <p>I am pretty new to Android. I am working on this project which displays a list of applications and it's details in a listview. I get the list of applications as a JsonArray from a server. I use a service to retrieve the JsonArray and a LocalBroadcastManager to broadcast it to the MainActivity. Everything works fine for me. But it takes a couple of seconds to get the data into my mainacitvity. This causes my app to display just a blank screen. Therefore I thought to add a Progress Dialogbox to display till I get the data from the service. I found an example to display Progress dialog box using Asynctask (link: <a href="https://stackoverflow.com/questions/14426356/how-to-use-progress-dialog-in-asynctask-in-android">How to use progress dialog in AsyncTask in android</a>). But my problem is that, I don't know how to implement my Broascast receiver method inside the Asyntask DoInBackground method.  I searched for some answers but couldn't find any. </p>
  
  <p>I will really appreciate if anyone could help me out with this, or suggest me an alternate method to do this. Thanks in Advance</p>
  
  <p><strong>My code:</strong> </p>
  
  <p>this is the method in the service class that, I'm using to broadcast the JSONArray to the mainActivity</p>
  
  <pre><code>private void broadcastMessage(String message, String extraType) {
      // TODO Auto-generated method stub
      Intent intent = new Intent("my-event");
      if (message != null){
          intent.putExtra(extraType, message);
      }
      LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
  }
  </code></pre>
  
  <p>message here contains my JSONArray as a String.</p>
  
  <p>Here is the code I'm using in the mainActivity to get the data:</p>
  
  <pre><code>LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver,
                new IntentFilter("my-event"));
  </code></pre>
  
  <p>Where mMessagerReceiver is an object of BroadcastReceiver.</p>
  
  <pre><code>private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() {
  
      @Override
      public void onReceive(Context context, Intent intent) {
          // TODO Auto-generated method stub
          results = intent.getStringExtra("JSONArray");
          Log.e("receiver", "got your message");
      }
  };
  </code></pre>
  
  <p>This code works fine with me.. But now I want the broascastReceiver to be within my asynctask. Is it possible to do?</p>