ARTICLE AD BOX
When I run the app and then navigate to another page then go to task switcher, flick the app to close and then re open, I can see that it is still using the same instance of the window. The app reopen and it's loading to the page where it was before closing. I'm trying to understand what could cause that behavior.
To give a better context, here's my code:
As you can see, the variable _window is being kept.
public App(IServiceProvider ServiceProvider, ILogger logger) { _logger = logger; _shell = ServiceProvider.GetService<AppShell>() ?? throw new Exception(); InitializeComponent(); } protected override Window CreateWindow(IActivationState? activationState) { if (_window != null) { _logger.WriteLog("CreateWindow: Window is not null"); return _window; } else { _logger.WriteLog("New Window"); _window = new(_shell); } return _window; }Now when I close the app and then reopen it, I can see from the logs that the Window is not null. I like that behavior, that allows the app to reload to the page where it was before closing.
Then, I created a new app with the same logic as above. But the new app doesn't have that behavior, the moment I flick the app to close and and then reopen it. It's always trying to create a new Window.
What am I missing? How can the old instance of the App class be retained after closing the app?
