I'm new to Xamarin and I'm looking for an entry point like a main() method. Also, I have a data storage (i.e. model) class, which constantly receives data from a web socket and shall be accessible from throughout the application (i.e. from multiple ViewModels). Where can I put significant and central classes like these? Would you put these in a static class?
Also: Is there something like a main-loop which is responsible for handling tasks and events?
I'd be very grateful for a generic/primer overview of all the "entry points" within a Xamarin application.
Each platform has their own main() like methods
MainActivity.OnCreate()
AppDelegate.FinishedLaunching(UIApplication app, NSDictionary options)
App.OnLaunched(LaunchActivatedEventArgs e)
on Xamarin.Forms applications all those platforms instantiates App class and sets the MainPage.
You should use App.OnStart() method if you want to do for BL.
If you for example create a Cross Platform Mobile App in Visual Studio 2017 you will already get a scaffold. The data layer is located in the 'Services' Folder.
I would consider the "App.xaml" file as your entry point.
public partial class App : Application
{
//TODO: Replace with *.azurewebsites.net url after deploying backend to Azure
public static string AzureBackendUrl = "http://localhost:5000";
public static bool UseMockDataStore = false;
public static bool UseEntityFramework = true;
public App()
{
InitializeComponent();
if (UseMockDataStore)
DependencyService.Register<MockDataStore>();
else if (UseEntityFramework)
DependencyService.Register<SqLiteDataStore>();
else
DependencyService.Register<AzureDataStore>();
MainPage = new MainPage();
}
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
}
}
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