Good day. I've got unexpected behaviour in my app. In solution use two projects - Android and UWP. So I try to get authorisation from server, so use async methods. Auth starts before main page loads, and I start it in App.xaml.cs. So here is the code:
public App() { InitializeComponent(); } protected async override void OnStart() { bool isUser = await accountManager.InitAsync(); if (isUser) MainPage = new NavigationPage(new MainPage()); else MainPage = new NavigationPage(new RegisterPage()); }
In accountManager.InitAsync(); I restore user from App.Dictionary and make POST request to a server, to check user in DB.
When I start UWP project it works as I thought - I get answer from server and get needed page. But when I start in in Android device no page is loaded - though accountManager.InitAsync(); sends post request and I get answer. And when I call OnStart from App(), it works as planned:
public App() { InitializeComponent(); OnStart(); } protected async override void OnStart() { bool isUser = await accountManager.InitAsync(); if (isUser) MainPage = new NavigationPage(new MainPage()); else MainPage = new NavigationPage(new RegisterPage()); }
But in this case I got 2 calls to a server, not critical, but wrong, as I suppose.
So why is it so? Should I change the logic to use async methods at app start? And what I do not understand in OnStart functionality?