dotnet / dotnet/maui

Add Generic Lifecycle Events

Open
#8,780 1 comment 12 reactions 0 assignees View on GitHub
area-core-lifecycle partner proposal/open
Dominant language
C#
Stars
23.3k
Forks
2k
Avg merge
1d 15h
Merged PRs (30d)
290

Description

### Description

The Application exposes methods to handle OnStart, OnSleep, & OnResume. It is technically possible to hook into these events if multi-targeting and providing native delegates for these Lifecycle Events. Since we already accept that these are platform agnostic events these should exist on the cross platform API for the LifecycleEvents builder.

### Public API Changes

This should be generally available on the net6.0 API so that it can be done generically to support any target without the need to explicitly provide a target for an individual platform.

```csharp
builder.ConfigureLifecycleEvents(lifecycle =>
{
lifecycle.OnStart(() => {
// My handler
});
lifecycle.OnSleep(() => {
// My handler
});
lifecycle.OnResume(() => {
// My handler
});
});
```

### Intended Use-Case

Provide handlers cross platform without the need for libraries like Prism to explicitly provide a compiled target for Android, iOS, Mac, Windows, Tizen, etc.

Contributor guide

Open the contributing guide

Research direction

Start at the LifecycleEvents builder and the existing Application OnStart, OnSleep, and OnResume APIs. Trace how platform-specific lifecycle handlers are exposed, then verify that generic handlers can be registered through the net6.0 API and work for the three events without requiring a target platform.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
desktop-dev, mobile-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.