how to wait for the android activity to fully resume after calling ZXing qr scanner
<p>I have an application which when starting requests a qr code from the user, and according to the qr scanned, a different fragment is loaded in the activity</p>

<p>I am using ZXing mobile scanner to do this</p>

<p>unfortunatelly the scanner returns a reply way before it shuts down and returns to the calling activity</p>

<p>this means that when I call the transaction code to replace the current fragment with the new one, the activity is not yet in the foreground so nothing happens</p>

<p>To solve this I created a ManualResetEvent (I'm using Xamarin, but I will use a Semaphore when I have to convert this to Android Studio) that I set before starting the scan , and then reset in the OnResume part of the activity</p>

<p>this seems to solve the problem, but it feels like there is a much better solution</p>

<p>Is there something I am missing?</p>

<p>thanks in advance for any help you can provide</p>

<p>Edit: the code I am currently using</p>

<pre><code>public class MyActivity : Activity {
    ManualResetEvent _has_resumed = new ManualResetEvent(false);

    .....


    protected override void OnResume() {
        base.OnResume();
        _has_resumed.Set();
    }

    ......

    void scan_qr(Action&lt;string&gt; finished_callback) {
        #region initialize the scanner
        MobileBarcodeScanner scanner = new MobileBarcodeScanner();
        MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions();
        options.UseNativeScanning = true; //use native scan
        options.AutoRotate = false;//do not rotate the screen
        options.PossibleFormats = new List&lt;BarcodeFormat&gt; { BarcodeFormat.QR_CODE }; // only allow qr_codes;
        #endregion
        #region perform the actual scan, when it finishes return to the main thread and execute the callback
        _has_resumed.Reset();
        scanner.Scan(this, options) //do scan
               .ContinueWith(result =&gt; {
                   _has_resumed.WaitOne();
                   return result.Result;
               })//wait until the activity has resumed
               .ContinueWith((task_result) =&gt; { //then return the result
                   Result result = task_result.Result;
                   if (result == null) {
                       show_toast( Resource.String.questions_select_error_no_qr_scanned );
                   } else {
                       finished_callback(result.Text);
                   }
              }, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext());
        #endregion
    }



}
</code></pre>