Search code examples
c#xamarinxamarin.androidzxing

Camera View Stucks on UI after capturing barcode successfully


I am having issue in Xamarin.Forms.Android with below scenario:

I am testing and able to reproduce issue in ZXing Xamarin.Forms sample.

In Samples -> FormsSample.Droid: I have created copy of CustomScanPage.cs and using copied page to scan barcode again after scanning successfully in first CustomScanPage.

I am not doing PopAsync with first CustomScanPage.

My issue is when I go to second CustomScanPage(say CustomScanPage1) I can see camera view is stucked to old captured barcode image. Although it captures barcode in background but UI is not updated as I can not see camera preview.

Means, Issue arises when I have already CustomScanPage in backstack.

Note: This happens in case of android only, working fine in iOS.

UPDATE 1:

Looks like issue is in this.Holder, it is common. May be Old View is displayed on SurfaceView due to this case. Also in Xamarin.Forms we are using things in portable which are common across platforms. So one Activity is used for every Page.

This is simple scenario: Page stucks right after you completed scan, that same stucked page is displayed on next page


Solution

  • I have this conclusion finally, SurfaceDestroyed event is not fired from Xamarin.Android ZXing library. It is called when Page is Poped out. (Additionally in iOS ShutDownCamera code surface view is destroyed, which is not present in android StopScanning method.)

    So, I made a workaround of removing previous page from stack and maintained it in somewhere, after scanning from next page, and going back inserted that persisted page again. So, I am just taking care that only one page which contains scanner will be there in stack.