How to use “goAsync” for broadcastReceiver?

You can find short explanation here.

Use goAsync() if you want to handoff the processing inside of your BroadcastReceiver‘s onReceive() method to another thread. The onReceive() method can then be finished there. The PendingResult is passed to the new thread and you have to call PendingResult.finish() to actually inform the system that this receiver can be recycled.

For example:

final PendingResult result = goAsync();
Thread thread = new Thread() {
   public void run() {
      int i;
      // Do processing
      result.setResultCode(i);
      result.finish();
   }
};
thread.start();

Leave a Comment