简体   繁体   中英

Why in Xamarin Android the method Statements are getting executed in Reverse order

Why in Xamarin Android the method Statements are getting executed in Reverse order Which means the 5 is being displayed First and then the 0 gets displayed.

I have done this

<Button HorizontalOptions="Center" VerticalOptions="Center" Text="Click To Connect" Clicked="Button_OnClicked"></Button>

        private void Button_OnClicked(object sender, EventArgs e)
        {
            DisplayAlert("0", "0", "OK");
            DisplayAlert("5", "5", "OK");
        }

The DisplayAlert method can also be used to capture a user's response by presenting two buttons and returning a boolean. To get a response from an alert, supply text for both buttons and await the method. After the user selects one of the options the answer will be returned to your code.

as Selvin said,if you call DisplayAlert("0", "0", "OK"); directly,it doesn't block your thread,you don't need to wait the response from the alert,it will call DisplayAlert("0", "0", "OK"); then call DisplayAlert("5", "5", "OK"); ,but from the user's point of view, you see the second alert first,it overrides the first alert.

if you want display the first alert first,you should use key word await ,it will wait for you to make a choice,then continue the second alert.

private async void Button_OnClicked(object sender, EventArgs e)
   {
      await DisplayAlert("0", "0", "OK");
      await DisplayAlert("5", "5", "OK");
   }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM