maui
maui copied to clipboard
Add cross-platform lifecycle events
Description
We have the docs: https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/app-lifecycle?view=net-maui-8.0 stating that the app window has cross-platform lifecycle events.
| Event | Description | Action to take |
|---|---|---|
| Created | This event is raised after the native window has been created. At this point the cross-platform window will have a native window handler, but the window might not be visible yet. | |
| Activated | This event is raised when the window has been activated, and is, or will become, the focused window. | |
| Deactivated | This event is raised when the window is no longer the focused window. However, the window might still be visible. | |
| Stopped | This event is raised when the window is no longer visible. There's no guarantee that an app will resume from this state, because it may be terminated by the operating system. | Disconnect from any long running processes, or cancel any pending requests that might consume device resources. |
| Resumed | This event is raised when an app resumes after being stopped. This event won't be raised the first time your app launches, and can only be raised if the Stopped event has previously been raised. | Subscribe to any required events, and refresh any content that's on the visible page. |
| Destroying | This event is raised when the native window is being destroyed and deallocated. The same cross-platform window might be used against a new native window when the app is reopened. | Remove any event subscriptions that you've attached to the native window. |
Actually only platform-dependent events can be hooked using ConfigureLifecycleEvents, cross-platform ones from the table above cannot and the reason seems unclear. We can consume these events only by overriding methods from App.cs (IApplication) but external code cannot access them.
The suggestion is to create a class like AppWindowLifecycle similar to, for example, WindowsLifecycle and start invoking these methods from the internal code.
Intended Use-Case
Wanted to provide an easy way to enhance the Maui App main Window using ConfigureLifecycleEvents but the only way remains to code inside App.cs overrides.
Also this would allow developers to consume lifecycle events in a more event-oriented manner instead of customizing App.cs.
Remains a low-priority suggestion, but still.
Duplicate of #999
reserved
@jfversluis - I agree with @taublast - this doesn't seem like a duplicate and, at least on its face, feels like sensible suggestion. Should we reopen, add [Enhancement] to the title and move it to the backlog? I'm not suggesting we prioritize doing it, just keeping it open to gather more feedback.
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.