When my app is first starting, I need to load up some previously saved data. If it exists -> then goto the TabbedPage page. Otherwise, a Login page.
I'm not sure how I can call my async method in the app's ctor or even in another method? How can I do this?
Here's my code..
namespace Foo
{
public class App : Application
{
public App()
{
Page page;
LoadStorageDataAsync(); // TODO: HALP!
if (Account != null)
{
// Lets show the dashboard.
page = new DashboardPage();
}
else
{
// We need to login to figure out who we are.
page = CreateAuthenticationPage();
}
MainPage = page;
}
... snip ...
}
So why is LoadStorageDataAsync
async? Because it's using the library PCLStorage and that is all async.
As far as the docs say, you have the Application.OnStart
event which you can override:
Application developers override this method to perform actions when the application starts.
You can execute your async
method there where it can actually be awaited:
public override async void OnStart()
{
await LoadStorageDataAsync();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With