Hello,
For the case of obtaining user information to determine the page display, it is recommended that you place it in the OnAppearing method of AppShell for the following reasons.
-
App.xaml.cs
is not a UI component. For UI initialization, it would be a better choice to write it inAppShell.xaml.cs
. -
HttpClient
initiates a request to the Service asynchronously, so it is necessary to use await when calling it, but theasync/await
keywords are not allowed in the constructor. Therefore, you can put this method in theOnAppearing
method ofAppShell.xaml.cs
to process this request when the UI is initialized.
protected override async void OnAppearing()
{
base.OnAppearing();
// Handle Http request here.
}
Best Regards,
Alec Liu.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.