Post Impatica
Post Impatica

Reputation: 16433

Zxing.Net in Xamarin.Forms won't return result on Android

I have a Xamarin.Forms app using the Zxing.Net barcode scanner and it runs fine in UWP but for some reason it will never return a result when I run it on an Android.

Upvotes: 0

Views: 180

Answers (1)

Post Impatica
Post Impatica

Reputation: 16433

I found the cause. I load a couple different type scan pages so I have this method in my root page that loads the type of scan page I want:

MessagingCenter.Subscribe<ILoginPageViewModel, string>(this, "NavigateTo", async (sender, args) => {
            Type type = Type.GetType($"MyApp.Interfaces.{args}, MyApp");
            var page = (Page)ViewModelLocator.Container.Resolve(type);
            await Navigation.PushAsync(page);
        });

The problem is the await Navigation.PushAsync(page); line.

Here was the fix:

MessagingCenter.Subscribe<ILoginPageViewModel, string>(this, "NavigateTo", (sender, args) => {
            Type type = Type.GetType($"MyApp.Interfaces.{args}, MyApp");
            var page = (Page)ViewModelLocator.Container.Resolve(type);
            Device.BeginInvokeOnMainThread(async () =>
            {
                await Navigation.PushAsync(page);
            });
        });

For some reason this was not a problem on UWP

Upvotes: 1

Related Questions