I am using the MauiCommunityToolkit and builder.ConfigureLifeCycleEvents in MauiProgram.cs like this:
// Initialise the toolkit
builder.UseMauiApp<App>().UseMauiCommunityToolkit();
// the rest of the logic...
builder.ConfigureLifecycleEvents(events =>
{
#if ANDROID
events.AddAndroid(android => android
.OnStart((activity) => MyOnStart(activity))
.OnCreate((activity, bundle) => MyOnCreate(activity, bundle))
.OnResume((activity) => MyOnResume(activity))
.OnBackPressed((activity) => MyOnBackPressed(activity))
.OnPause((activity) => MyOnPause(activity))
.OnStop((activity) => MyOnStop(activity))
.OnDestroy((activity) => MyOnDestroy(activity)));
#endif
});
This is all good, but is there some way to subscribe to these events directly from a ViewModel? I could use the messenger service to let the ViewModel know if these events are fired if not. Is there a better way? I am new to MAUI (and this may be a C# question anyway).