Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XPlat Window Lifecycle #1720

Closed
Redth opened this issue Jul 16, 2021 · 6 comments
Closed

XPlat Window Lifecycle #1720

Redth opened this issue Jul 16, 2021 · 6 comments
Assignees
Labels
fixed-in-6.0.100-preview.7.3 Look for this fix in 6.0.100-preview.7.3!

Comments

@Redth
Copy link
Member

Redth commented Jul 16, 2021

LifeCycle

Window

Event Description Use Cases
Created After the native concept of the window has been created. At this point the XPlat window will have a native window handler but the window might not be visible yet Register Windows or other services that are needed before a window comes into existence
Resumed This will fire when an application is resumed after being stopped. It won't run the first time your app launches it will only fire after the app has passed through the stopped life cycle event You can use this to rewire up events or refresh anything that's on the currently visible page
Activated This window has been activated and is/will become the focused window
Deactivated This window is no longer the active/focused window. The window still might be visible. For example on Android with a permission dialog pops up the activity will become deactivated but it will still be visible behind the dialog This window has lost focus
Stopped The window is no longer visible to the user. There's no promise that an app will return from Stopped. Android might destroy the activity after it has been stopped disconnect from any long running processes or cancel any pending requests that might tie up device resources
Destroying Native window is being destroyed and deallocated. This indicates that the native representation of the window is being destroyed. The same xplat window might be used against a new native window when the user re-opens the app or navigates to it from URI/Navigation. I've picked the term Destroying over Closing because it's the opposite of Created and I feel that Closing represents an explicit action where the user has expressed that they no longer want anything to do with a window. Closing will makes sense once we have multi-window. Remove any events you've wired into the native window.

Platform Mappings

Event iOS WinUI Android
Created FinishedLaunching OnLaunched after native/xplat window is created OnPostCreate
Resumed WillEnterForeground OnActivated (once a window is activated a 2nd time) OnRestart
Activated OnActivated OnActivated (CodeActivated/PointerActivated) OnResume
Deactivated OnResignActivation OnActivated (Deactivated) OnPause
Stopped DidEnterBackground OnVisibilityChanged OnStop
Destroying WillTerminate OnClosed OnDestroy
@Redth Redth added this to the 6.0.100-preview.7 milestone Jul 16, 2021
@Redth
Copy link
Member Author

Redth commented Jul 16, 2021

.

@pjmagee
Copy link

pjmagee commented Jul 16, 2021

  • Resume
  • Sleep (Paused)
  • Start

Why no Closed?

For example can I use this Window Lifecycle to hook into starting some background tasks and then use this for ending those background tasks gracefully?

Currently for WinUI i am using (But i want to also have this app run on a Mac)

MainWindow.Closed += (sender, e) =>
            {
                Initializer.Stop();
            };

@AmrAlSayed0
Copy link
Contributor

@pjmagee I don't think iOS or Android support running code before an app is closed. Android can decide to kill an app any time it is in the background.

Though it could be worth adding for the sake of completeness. Usually, you will be doing the same action in OnPause and OnClose. Actually, Android recommends you treat OnPause as if it was OnClose and assume that the app isn't coming back to the foreground.

@pjmagee
Copy link

pjmagee commented Jul 16, 2021

@pjmagee I don't think iOS or Android support running code before an app is closed. Android can decide to kill an app any time it is in the background.

Though it could be worth adding for the sake of completeness. Usually, you will be doing the same action in OnPause and OnClose. Actually, Android recommends you treat OnPause as if it was OnClose and assume that the app isn't coming back to the foreground.

So using Maui Blazor purely for desktop on Windows / Mac. I should be able to use OnPause and assume the Window was just closed? - Application terminated, Not Minimized.

@Eilon
Copy link
Member

Eilon commented Jul 19, 2021

I'm not super familiar with the specifics on this question, but in .NET MAUI (including Blazor Desktop, such as .NET MAUI + Blazor), if you know which platform you're running on, you can use any platform-specific API that you want. So if on Windows (in WinUI) there's some API you want to use (including any Win32 native API), you can use that for whatever you want. But I don't know specifically about pause/resume behaviors and what each OS offers.

@PureWeen
Copy link
Member

@AmrAlSayed0 @pjmagee

I've updated the spec here with a couple more events and some additional justification for my decisions.

Let me know your thoughts

@ghost ghost locked as resolved and limited conversation to collaborators Feb 19, 2022
@samhouts samhouts added the fixed-in-6.0.100-preview.7.3 Look for this fix in 6.0.100-preview.7.3! label Jul 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-6.0.100-preview.7.3 Look for this fix in 6.0.100-preview.7.3!
Projects
None yet
Development

No branches or pull requests

6 participants