Why DisplayAlert does not work in constructor?












0














I have some problems in my Xamarin.Forms app related to invoking async method in the page constructor so when I test something trying to figure out the reason I just realized DisplayAlert method does not even work in the page constructor so I am wondering why is that happening?



Here is my code:



    public MainPage ()
{
InitializeComponent ();
DisplayAlert("An alert", "Why I don't show up?", "Ok");
}


and I also tried to call async method that has DisplayAlert method but didn't work too, here is the code:



    public MainPage ()
{
InitializeComponent ();
Async_Function_Has_DisplayAlert();
}
async void Async_Function_Has_DisplayAlert()
{
// I tried both and neither of them worked
await DisplayAlert("An alert", "Why I don't show up?", "Ok");
await Task.Run(()=> DisplayAlert("An alert", "Why I don't show up?", "Ok"));
}


So can someone explain why that is happening please?










share|improve this question






















  • Can you check if my solutions help?
    – Amadeu Antunes
    Nov 17 '18 at 0:55






  • 1




    the constructor runs before the UI of the page has been built. Use OnAppearing() instead
    – Jason
    Nov 17 '18 at 1:22
















0














I have some problems in my Xamarin.Forms app related to invoking async method in the page constructor so when I test something trying to figure out the reason I just realized DisplayAlert method does not even work in the page constructor so I am wondering why is that happening?



Here is my code:



    public MainPage ()
{
InitializeComponent ();
DisplayAlert("An alert", "Why I don't show up?", "Ok");
}


and I also tried to call async method that has DisplayAlert method but didn't work too, here is the code:



    public MainPage ()
{
InitializeComponent ();
Async_Function_Has_DisplayAlert();
}
async void Async_Function_Has_DisplayAlert()
{
// I tried both and neither of them worked
await DisplayAlert("An alert", "Why I don't show up?", "Ok");
await Task.Run(()=> DisplayAlert("An alert", "Why I don't show up?", "Ok"));
}


So can someone explain why that is happening please?










share|improve this question






















  • Can you check if my solutions help?
    – Amadeu Antunes
    Nov 17 '18 at 0:55






  • 1




    the constructor runs before the UI of the page has been built. Use OnAppearing() instead
    – Jason
    Nov 17 '18 at 1:22














0












0








0







I have some problems in my Xamarin.Forms app related to invoking async method in the page constructor so when I test something trying to figure out the reason I just realized DisplayAlert method does not even work in the page constructor so I am wondering why is that happening?



Here is my code:



    public MainPage ()
{
InitializeComponent ();
DisplayAlert("An alert", "Why I don't show up?", "Ok");
}


and I also tried to call async method that has DisplayAlert method but didn't work too, here is the code:



    public MainPage ()
{
InitializeComponent ();
Async_Function_Has_DisplayAlert();
}
async void Async_Function_Has_DisplayAlert()
{
// I tried both and neither of them worked
await DisplayAlert("An alert", "Why I don't show up?", "Ok");
await Task.Run(()=> DisplayAlert("An alert", "Why I don't show up?", "Ok"));
}


So can someone explain why that is happening please?










share|improve this question













I have some problems in my Xamarin.Forms app related to invoking async method in the page constructor so when I test something trying to figure out the reason I just realized DisplayAlert method does not even work in the page constructor so I am wondering why is that happening?



Here is my code:



    public MainPage ()
{
InitializeComponent ();
DisplayAlert("An alert", "Why I don't show up?", "Ok");
}


and I also tried to call async method that has DisplayAlert method but didn't work too, here is the code:



    public MainPage ()
{
InitializeComponent ();
Async_Function_Has_DisplayAlert();
}
async void Async_Function_Has_DisplayAlert()
{
// I tried both and neither of them worked
await DisplayAlert("An alert", "Why I don't show up?", "Ok");
await Task.Run(()=> DisplayAlert("An alert", "Why I don't show up?", "Ok"));
}


So can someone explain why that is happening please?







xamarin.forms






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 23:59









Ahmed Salah

1911214




1911214












  • Can you check if my solutions help?
    – Amadeu Antunes
    Nov 17 '18 at 0:55






  • 1




    the constructor runs before the UI of the page has been built. Use OnAppearing() instead
    – Jason
    Nov 17 '18 at 1:22


















  • Can you check if my solutions help?
    – Amadeu Antunes
    Nov 17 '18 at 0:55






  • 1




    the constructor runs before the UI of the page has been built. Use OnAppearing() instead
    – Jason
    Nov 17 '18 at 1:22
















Can you check if my solutions help?
– Amadeu Antunes
Nov 17 '18 at 0:55




Can you check if my solutions help?
– Amadeu Antunes
Nov 17 '18 at 0:55




1




1




the constructor runs before the UI of the page has been built. Use OnAppearing() instead
– Jason
Nov 17 '18 at 1:22




the constructor runs before the UI of the page has been built. Use OnAppearing() instead
– Jason
Nov 17 '18 at 1:22












3 Answers
3






active

oldest

votes


















0














Normally, you should not call an awaitable method like DisplayAlert() from the constructor.
What you can do is have a method that returns void (still not best practice) and call that method from your constructor.



Tweaking my recommendation after trying it out.
I used Device.Timer to delay the alert.
I think some components have not finished loading (in this case, the DisplayAlert) before trying to call it.



public MainPage()
{
InitializeComponent();
Device.StartTimer(TimeSpan.FromSeconds(4), () =>
{
ShowMessage();
return false; // True = Repeat again, False = Stop the timer
});
}
public async void ShowMessage()
{

await DisplayAlert("Alert", "I show here", "OK");

}


enter image description here






share|improve this answer























  • Do you mean some strategy other than my second sample code?
    – Ahmed Salah
    Nov 17 '18 at 19:31










  • I just tried what I advised. It didn't work. See my edited answer.
    – Dara Oladapo
    Nov 18 '18 at 23:36












  • @DaraOladapo Even though your solution is straight forward, I would not recommend it. What you are doing there is betting on having a finished page ready to work with in 4 seconds. This would probably work very fine in 99.9% of all cases, but you never get any guarantee that your UI is ready to call the DisplayAlert(). For instance, if your app runs on a slow phone and your UI is doing some very complex layouting, it could take longer than 4 seconds to build the page, which would result in your app behaving non-deterministic. The best approach is to call DisplayAlert in OnAppearing()
    – Markus Michel
    Nov 19 '18 at 8:04










  • I'm inclined to agree with you @MarkusMichel after trying it out.
    – Dara Oladapo
    Nov 19 '18 at 11:07



















0














There seems to be a misconception on what is happening in the constructor.
The constructor simply creates a new Page class.



CustomMainPage mainpage = new CustomMainPage();
(App.Current as App).MainPage = new NavigationPage(mainpage);


So before we add the mainpage class to the NavigationPage, all that has happened is that the CustomMainPage class was initialized and is ready to be inserted into an appropriate container.
However after creating the new page, there is no actual UI on the screen, yet. For instance, the mainpage object wouldn't have width or height set, no layout has been done, etc...
If you run a UI related task, such as presenting an Alert, there isn't simply any foundation for it there, which could do anything resonable.



Of course you could already set members of the mainpage, such as labels or buttons to certain values, colors, styles or whatever you want, from within the constructor, but these wouldn't do anything at that point of time.
All of those values will be taken into account when the page is being layouted and presented but none of that will happen in the constructor.



However, back to your problem: You seemingly want to inform the user that something has gone wrong during the initialization.



I see two ways of adressing that issue:




  1. Check the preconditions on the page or within the code before initializing your view and present the Alert from the page or class, which is initializing your page.

  2. create a private variable in your page class, which you will set from within your page constructor if something goes wrong. This could be a simple bool flag, a string containing an error message, an enum or whatever suits your needs. Then override the OnAppearing() method, check that flag you set earlier and call DisplayAlert depending on the flag's value.


If you want any interactivity on your page, then you should consider Jason's comment to your question and implement it within OnAppearing, because this method will be called once your page has been fully layouted and is being presented on your screen.






share|improve this answer





























    0














    Sample code for Jason's recommendation



    public async void ShowMessage()
    {
    await DisplayAlert("Alert", "I show here", "OK");
    }
    protected override void OnAppearing()
    {
    ShowMessage();
    }





    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346910%2fwhy-displayalert-does-not-work-in-constructor%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Normally, you should not call an awaitable method like DisplayAlert() from the constructor.
      What you can do is have a method that returns void (still not best practice) and call that method from your constructor.



      Tweaking my recommendation after trying it out.
      I used Device.Timer to delay the alert.
      I think some components have not finished loading (in this case, the DisplayAlert) before trying to call it.



      public MainPage()
      {
      InitializeComponent();
      Device.StartTimer(TimeSpan.FromSeconds(4), () =>
      {
      ShowMessage();
      return false; // True = Repeat again, False = Stop the timer
      });
      }
      public async void ShowMessage()
      {

      await DisplayAlert("Alert", "I show here", "OK");

      }


      enter image description here






      share|improve this answer























      • Do you mean some strategy other than my second sample code?
        – Ahmed Salah
        Nov 17 '18 at 19:31










      • I just tried what I advised. It didn't work. See my edited answer.
        – Dara Oladapo
        Nov 18 '18 at 23:36












      • @DaraOladapo Even though your solution is straight forward, I would not recommend it. What you are doing there is betting on having a finished page ready to work with in 4 seconds. This would probably work very fine in 99.9% of all cases, but you never get any guarantee that your UI is ready to call the DisplayAlert(). For instance, if your app runs on a slow phone and your UI is doing some very complex layouting, it could take longer than 4 seconds to build the page, which would result in your app behaving non-deterministic. The best approach is to call DisplayAlert in OnAppearing()
        – Markus Michel
        Nov 19 '18 at 8:04










      • I'm inclined to agree with you @MarkusMichel after trying it out.
        – Dara Oladapo
        Nov 19 '18 at 11:07
















      0














      Normally, you should not call an awaitable method like DisplayAlert() from the constructor.
      What you can do is have a method that returns void (still not best practice) and call that method from your constructor.



      Tweaking my recommendation after trying it out.
      I used Device.Timer to delay the alert.
      I think some components have not finished loading (in this case, the DisplayAlert) before trying to call it.



      public MainPage()
      {
      InitializeComponent();
      Device.StartTimer(TimeSpan.FromSeconds(4), () =>
      {
      ShowMessage();
      return false; // True = Repeat again, False = Stop the timer
      });
      }
      public async void ShowMessage()
      {

      await DisplayAlert("Alert", "I show here", "OK");

      }


      enter image description here






      share|improve this answer























      • Do you mean some strategy other than my second sample code?
        – Ahmed Salah
        Nov 17 '18 at 19:31










      • I just tried what I advised. It didn't work. See my edited answer.
        – Dara Oladapo
        Nov 18 '18 at 23:36












      • @DaraOladapo Even though your solution is straight forward, I would not recommend it. What you are doing there is betting on having a finished page ready to work with in 4 seconds. This would probably work very fine in 99.9% of all cases, but you never get any guarantee that your UI is ready to call the DisplayAlert(). For instance, if your app runs on a slow phone and your UI is doing some very complex layouting, it could take longer than 4 seconds to build the page, which would result in your app behaving non-deterministic. The best approach is to call DisplayAlert in OnAppearing()
        – Markus Michel
        Nov 19 '18 at 8:04










      • I'm inclined to agree with you @MarkusMichel after trying it out.
        – Dara Oladapo
        Nov 19 '18 at 11:07














      0












      0








      0






      Normally, you should not call an awaitable method like DisplayAlert() from the constructor.
      What you can do is have a method that returns void (still not best practice) and call that method from your constructor.



      Tweaking my recommendation after trying it out.
      I used Device.Timer to delay the alert.
      I think some components have not finished loading (in this case, the DisplayAlert) before trying to call it.



      public MainPage()
      {
      InitializeComponent();
      Device.StartTimer(TimeSpan.FromSeconds(4), () =>
      {
      ShowMessage();
      return false; // True = Repeat again, False = Stop the timer
      });
      }
      public async void ShowMessage()
      {

      await DisplayAlert("Alert", "I show here", "OK");

      }


      enter image description here






      share|improve this answer














      Normally, you should not call an awaitable method like DisplayAlert() from the constructor.
      What you can do is have a method that returns void (still not best practice) and call that method from your constructor.



      Tweaking my recommendation after trying it out.
      I used Device.Timer to delay the alert.
      I think some components have not finished loading (in this case, the DisplayAlert) before trying to call it.



      public MainPage()
      {
      InitializeComponent();
      Device.StartTimer(TimeSpan.FromSeconds(4), () =>
      {
      ShowMessage();
      return false; // True = Repeat again, False = Stop the timer
      });
      }
      public async void ShowMessage()
      {

      await DisplayAlert("Alert", "I show here", "OK");

      }


      enter image description here







      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 18 '18 at 23:45

























      answered Nov 17 '18 at 4:45









      Dara Oladapo

      796




      796












      • Do you mean some strategy other than my second sample code?
        – Ahmed Salah
        Nov 17 '18 at 19:31










      • I just tried what I advised. It didn't work. See my edited answer.
        – Dara Oladapo
        Nov 18 '18 at 23:36












      • @DaraOladapo Even though your solution is straight forward, I would not recommend it. What you are doing there is betting on having a finished page ready to work with in 4 seconds. This would probably work very fine in 99.9% of all cases, but you never get any guarantee that your UI is ready to call the DisplayAlert(). For instance, if your app runs on a slow phone and your UI is doing some very complex layouting, it could take longer than 4 seconds to build the page, which would result in your app behaving non-deterministic. The best approach is to call DisplayAlert in OnAppearing()
        – Markus Michel
        Nov 19 '18 at 8:04










      • I'm inclined to agree with you @MarkusMichel after trying it out.
        – Dara Oladapo
        Nov 19 '18 at 11:07


















      • Do you mean some strategy other than my second sample code?
        – Ahmed Salah
        Nov 17 '18 at 19:31










      • I just tried what I advised. It didn't work. See my edited answer.
        – Dara Oladapo
        Nov 18 '18 at 23:36












      • @DaraOladapo Even though your solution is straight forward, I would not recommend it. What you are doing there is betting on having a finished page ready to work with in 4 seconds. This would probably work very fine in 99.9% of all cases, but you never get any guarantee that your UI is ready to call the DisplayAlert(). For instance, if your app runs on a slow phone and your UI is doing some very complex layouting, it could take longer than 4 seconds to build the page, which would result in your app behaving non-deterministic. The best approach is to call DisplayAlert in OnAppearing()
        – Markus Michel
        Nov 19 '18 at 8:04










      • I'm inclined to agree with you @MarkusMichel after trying it out.
        – Dara Oladapo
        Nov 19 '18 at 11:07
















      Do you mean some strategy other than my second sample code?
      – Ahmed Salah
      Nov 17 '18 at 19:31




      Do you mean some strategy other than my second sample code?
      – Ahmed Salah
      Nov 17 '18 at 19:31












      I just tried what I advised. It didn't work. See my edited answer.
      – Dara Oladapo
      Nov 18 '18 at 23:36






      I just tried what I advised. It didn't work. See my edited answer.
      – Dara Oladapo
      Nov 18 '18 at 23:36














      @DaraOladapo Even though your solution is straight forward, I would not recommend it. What you are doing there is betting on having a finished page ready to work with in 4 seconds. This would probably work very fine in 99.9% of all cases, but you never get any guarantee that your UI is ready to call the DisplayAlert(). For instance, if your app runs on a slow phone and your UI is doing some very complex layouting, it could take longer than 4 seconds to build the page, which would result in your app behaving non-deterministic. The best approach is to call DisplayAlert in OnAppearing()
      – Markus Michel
      Nov 19 '18 at 8:04




      @DaraOladapo Even though your solution is straight forward, I would not recommend it. What you are doing there is betting on having a finished page ready to work with in 4 seconds. This would probably work very fine in 99.9% of all cases, but you never get any guarantee that your UI is ready to call the DisplayAlert(). For instance, if your app runs on a slow phone and your UI is doing some very complex layouting, it could take longer than 4 seconds to build the page, which would result in your app behaving non-deterministic. The best approach is to call DisplayAlert in OnAppearing()
      – Markus Michel
      Nov 19 '18 at 8:04












      I'm inclined to agree with you @MarkusMichel after trying it out.
      – Dara Oladapo
      Nov 19 '18 at 11:07




      I'm inclined to agree with you @MarkusMichel after trying it out.
      – Dara Oladapo
      Nov 19 '18 at 11:07













      0














      There seems to be a misconception on what is happening in the constructor.
      The constructor simply creates a new Page class.



      CustomMainPage mainpage = new CustomMainPage();
      (App.Current as App).MainPage = new NavigationPage(mainpage);


      So before we add the mainpage class to the NavigationPage, all that has happened is that the CustomMainPage class was initialized and is ready to be inserted into an appropriate container.
      However after creating the new page, there is no actual UI on the screen, yet. For instance, the mainpage object wouldn't have width or height set, no layout has been done, etc...
      If you run a UI related task, such as presenting an Alert, there isn't simply any foundation for it there, which could do anything resonable.



      Of course you could already set members of the mainpage, such as labels or buttons to certain values, colors, styles or whatever you want, from within the constructor, but these wouldn't do anything at that point of time.
      All of those values will be taken into account when the page is being layouted and presented but none of that will happen in the constructor.



      However, back to your problem: You seemingly want to inform the user that something has gone wrong during the initialization.



      I see two ways of adressing that issue:




      1. Check the preconditions on the page or within the code before initializing your view and present the Alert from the page or class, which is initializing your page.

      2. create a private variable in your page class, which you will set from within your page constructor if something goes wrong. This could be a simple bool flag, a string containing an error message, an enum or whatever suits your needs. Then override the OnAppearing() method, check that flag you set earlier and call DisplayAlert depending on the flag's value.


      If you want any interactivity on your page, then you should consider Jason's comment to your question and implement it within OnAppearing, because this method will be called once your page has been fully layouted and is being presented on your screen.






      share|improve this answer


























        0














        There seems to be a misconception on what is happening in the constructor.
        The constructor simply creates a new Page class.



        CustomMainPage mainpage = new CustomMainPage();
        (App.Current as App).MainPage = new NavigationPage(mainpage);


        So before we add the mainpage class to the NavigationPage, all that has happened is that the CustomMainPage class was initialized and is ready to be inserted into an appropriate container.
        However after creating the new page, there is no actual UI on the screen, yet. For instance, the mainpage object wouldn't have width or height set, no layout has been done, etc...
        If you run a UI related task, such as presenting an Alert, there isn't simply any foundation for it there, which could do anything resonable.



        Of course you could already set members of the mainpage, such as labels or buttons to certain values, colors, styles or whatever you want, from within the constructor, but these wouldn't do anything at that point of time.
        All of those values will be taken into account when the page is being layouted and presented but none of that will happen in the constructor.



        However, back to your problem: You seemingly want to inform the user that something has gone wrong during the initialization.



        I see two ways of adressing that issue:




        1. Check the preconditions on the page or within the code before initializing your view and present the Alert from the page or class, which is initializing your page.

        2. create a private variable in your page class, which you will set from within your page constructor if something goes wrong. This could be a simple bool flag, a string containing an error message, an enum or whatever suits your needs. Then override the OnAppearing() method, check that flag you set earlier and call DisplayAlert depending on the flag's value.


        If you want any interactivity on your page, then you should consider Jason's comment to your question and implement it within OnAppearing, because this method will be called once your page has been fully layouted and is being presented on your screen.






        share|improve this answer
























          0












          0








          0






          There seems to be a misconception on what is happening in the constructor.
          The constructor simply creates a new Page class.



          CustomMainPage mainpage = new CustomMainPage();
          (App.Current as App).MainPage = new NavigationPage(mainpage);


          So before we add the mainpage class to the NavigationPage, all that has happened is that the CustomMainPage class was initialized and is ready to be inserted into an appropriate container.
          However after creating the new page, there is no actual UI on the screen, yet. For instance, the mainpage object wouldn't have width or height set, no layout has been done, etc...
          If you run a UI related task, such as presenting an Alert, there isn't simply any foundation for it there, which could do anything resonable.



          Of course you could already set members of the mainpage, such as labels or buttons to certain values, colors, styles or whatever you want, from within the constructor, but these wouldn't do anything at that point of time.
          All of those values will be taken into account when the page is being layouted and presented but none of that will happen in the constructor.



          However, back to your problem: You seemingly want to inform the user that something has gone wrong during the initialization.



          I see two ways of adressing that issue:




          1. Check the preconditions on the page or within the code before initializing your view and present the Alert from the page or class, which is initializing your page.

          2. create a private variable in your page class, which you will set from within your page constructor if something goes wrong. This could be a simple bool flag, a string containing an error message, an enum or whatever suits your needs. Then override the OnAppearing() method, check that flag you set earlier and call DisplayAlert depending on the flag's value.


          If you want any interactivity on your page, then you should consider Jason's comment to your question and implement it within OnAppearing, because this method will be called once your page has been fully layouted and is being presented on your screen.






          share|improve this answer












          There seems to be a misconception on what is happening in the constructor.
          The constructor simply creates a new Page class.



          CustomMainPage mainpage = new CustomMainPage();
          (App.Current as App).MainPage = new NavigationPage(mainpage);


          So before we add the mainpage class to the NavigationPage, all that has happened is that the CustomMainPage class was initialized and is ready to be inserted into an appropriate container.
          However after creating the new page, there is no actual UI on the screen, yet. For instance, the mainpage object wouldn't have width or height set, no layout has been done, etc...
          If you run a UI related task, such as presenting an Alert, there isn't simply any foundation for it there, which could do anything resonable.



          Of course you could already set members of the mainpage, such as labels or buttons to certain values, colors, styles or whatever you want, from within the constructor, but these wouldn't do anything at that point of time.
          All of those values will be taken into account when the page is being layouted and presented but none of that will happen in the constructor.



          However, back to your problem: You seemingly want to inform the user that something has gone wrong during the initialization.



          I see two ways of adressing that issue:




          1. Check the preconditions on the page or within the code before initializing your view and present the Alert from the page or class, which is initializing your page.

          2. create a private variable in your page class, which you will set from within your page constructor if something goes wrong. This could be a simple bool flag, a string containing an error message, an enum or whatever suits your needs. Then override the OnAppearing() method, check that flag you set earlier and call DisplayAlert depending on the flag's value.


          If you want any interactivity on your page, then you should consider Jason's comment to your question and implement it within OnAppearing, because this method will be called once your page has been fully layouted and is being presented on your screen.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 19 '18 at 9:28









          Markus Michel

          1,437314




          1,437314























              0














              Sample code for Jason's recommendation



              public async void ShowMessage()
              {
              await DisplayAlert("Alert", "I show here", "OK");
              }
              protected override void OnAppearing()
              {
              ShowMessage();
              }





              share|improve this answer


























                0














                Sample code for Jason's recommendation



                public async void ShowMessage()
                {
                await DisplayAlert("Alert", "I show here", "OK");
                }
                protected override void OnAppearing()
                {
                ShowMessage();
                }





                share|improve this answer
























                  0












                  0








                  0






                  Sample code for Jason's recommendation



                  public async void ShowMessage()
                  {
                  await DisplayAlert("Alert", "I show here", "OK");
                  }
                  protected override void OnAppearing()
                  {
                  ShowMessage();
                  }





                  share|improve this answer












                  Sample code for Jason's recommendation



                  public async void ShowMessage()
                  {
                  await DisplayAlert("Alert", "I show here", "OK");
                  }
                  protected override void OnAppearing()
                  {
                  ShowMessage();
                  }






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 19 '18 at 11:15









                  Dara Oladapo

                  796




                  796






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53346910%2fwhy-displayalert-does-not-work-in-constructor%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      How to change which sound is reproduced for terminal bell?

                      Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                      Can I use Tabulator js library in my java Spring + Thymeleaf project?