how to wait for sendBroadcast to finish
<p>I am doing a media  file scan using sendBroadcast. Then I need to wait till it's complete after doing sendBroadcast. How do I do this in Android ?</p>

<p>I know I can use a simple while logic here but I am looking for a better approach</p>

<pre><code>context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

// wait here till till do something completed
</code></pre>

<p>Receiver</p>

<pre><code>private BroadcastReceiver mediaScanner = new BroadcastReceiver(){

        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
                if (action.equals(Intent.ACTION_MEDIA_SCANNER_FINISHED)) {
                  // Do some thing here. 
                }
    }
}
</code></pre>
