1

Weird situation. DisplayAlert, in a XF app, is working in the emulator, in a Huawei Y9 (Android 9), but not in a Huawei Y9 Prime (Android 10). Is not poping and freezes the app.

The code to show it:

if (LocalSession.Device.IDDevice == 0) // Does not exist as registered device
{
   Device.BeginInvokeOnMainThread(() =>
   {
      DisplayAlert("Atención", "No existe el dispositivo en el sistema. Consulte al administrador. IMEI:" + LocalSession.IMEI, "Aceptar").Wait();
   });
}

Also tested without the Device.BeginInvokeOnMainThread and still not working.

Any direction will be appreciated.

HUAWEI Y9 Prime - EMUI -10.0.0.427

Nane
  • 318
  • 1
  • 8
  • 18

2 Answers2

2

It is highly likely that calling .Wait() will result in the UI thread being blocked and cause the deadlock.

There are lots of good answers on here already on this topic (e.g. https://stackoverflow.com/a/13140963/32348)

You should try using await instead:

if (LocalSession.Device.IDDevice == 0) // Does not exist as registered device
{
   Device.BeginInvokeOnMainThread(async () =>
   {
      await DisplayAlert("Atención", "No existe el dispositivo en el sistema. Consulte al administrador. IMEI:" + LocalSession.IMEI, "Aceptar");
   });
}
Bijington
  • 3,661
  • 5
  • 35
  • 52
1

The app freezes because you are using .Wait() instead of await. I would try it like this: await DisplayAlert("Atención", "No existe el dispositivo en el sistema. Consulte al administrador. IMEI:" + LocalSession.IMEI, "Aceptar");

If the Popup still doesn’t appear, you can try opening it from the current MainPage like this: await App.Current.MainPage.DisplayAlert("Atención", "No existe el dispositivo en el sistema. Consulte al administrador. IMEI:" + LocalSession.IMEI, "Aceptar");

Dharman
  • 30,962
  • 25
  • 85
  • 135
WorldOfBasti
  • 103
  • 1
  • 10