Xamarin Forms has the following App class:
public class App : Application
{
public App()
{
// The root page of your application
MainPage = new ContentPage
{
Content = new StackLayout
{
VerticalOptions = LayoutOptions.Center,
Children = {
new Label {
XAlign = TextAlignment.Center,
Text = "Welcome to Xamarin Forms!"
}
}
}
};
}
protected override void OnStart()
{
// Handle when your app starts
}
protected override void OnSleep()
{
// Handle when your app sleeps
}
protected override void OnResume()
{
// Handle when your app resumes
}
}
QUESTION: What is the difference between the code that runs in the constructor and the code written in the OnStart method. Aren't both run when your application starts?
see http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/app-lifecycle/ for more information.
They are completely different however the documentation is less than sparse.
Constructors are platform-agnostic and for the purpose of creating the object (apologies if this sounds like 'teaching you to suck eggs').
The OnStart() method however is mapped to the platform specific notification and its relevant meaning. This is the cross-platform implementation of each varying operating systems start up notification system - this will of course be different between the platforms but this abstraction allows you to handle it in an identical fashion.
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