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

Maui application does not restart properly after android activity is destroyed #18845

Open
tranb3r opened this issue Nov 17, 2023 · 6 comments
Open
Labels
area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@tranb3r
Copy link

tranb3r commented Nov 17, 2023

Description

When starting a Maui Application, the App constructor is called first, then the OnStart method is called.
But if Android kills the Activity, then no method from App is called when relaunching the application.
I would expect either the constructor or OnStart or OnResume to be called.

More details about events/methods being called during the lifecycle of an app (logs added to my repro):

  • start application
App: Create
Lifecycle: OnCreate
Lifecycle: OnStart
App: OnStart
Lifecycle: OnResume
  • application goes to background
Lifecycle: OnPause
App: OnSleep
Lifecycle: OnStop
  • application resumes
App: OnResume
Lifecycle: OnRestart
Lifecycle: OnStart
Lifecycle: OnResume
  • destroy activity
Finish activity
Lifecycle: OnPause
App: OnSleep
Lifecycle: OnStop
Lifecycle: OnDestroy
  • restart application ( <-- issue here )
Lifecycle: OnCreate
Lifecycle: OnStart
Lifecycle: OnResume

Steps to Reproduce

  1. Open repro project
  2. Launch application. Check app logs.
  3. Press Finish to simulate android killing the activity. Check app logs.
  4. Restart the application. Check app logs.

Link to public reproduction project repository

https://github.com/tranb3r/Issues/tree/main/MauiAppLifecycleIssue

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 14

Did you find any workaround?

No response

Relevant log output

No response

@tranb3r tranb3r added the t/bug Something isn't working label Nov 17, 2023
@christianrr
Copy link

christianrr commented Dec 13, 2023

This happens quite frequently on Pixel devices, as activities get temporarily closed for performance reasons (happens often overnight). If this happens, no app method is called for proper app recovery.

Probably there are some other recovery issues as well if activities are restored by OS. For instance, the Mopups PopupStack contains visible popups although the activity's DecorView is empty (= popup windows are gone).

.net MAUI 8.0.3, Android 13 & 14

@christianrr
Copy link

Our workaround is currently to call App.Current.Quit() in MainActivity's OnDestroy.
Thus, we force a clean restart of the application including OnStart();

@tranb3r
Copy link
Author

tranb3r commented Dec 13, 2023

Our workaround is currently to call App.Current.Quit() in MainActivity's OnDestroy. Thus, we force a clean restart of the application including OnStart();

This is also what I'm doing.

@ninachen03
Copy link

Verified this issue with Visual Studio 17.10.0 Preview 3 (8.0.20 & 8.0.0-rc.2.9530),I can repro it.
image

@PureWeen
Copy link
Member

I'm guessing the life cycle events you want are on the window

Try creating your own window type
https://learn.microsoft.com/en-us/dotnet/maui/fundamentals/windows?view=net-maui-8.0#create-a-window

And see about override the lifecycle methods on there

@jsuarezruiz jsuarezruiz added this to the Backlog milestone Jun 6, 2024
@dalux-era
Copy link

We are also experiencing a problem when Android OS shuts down the activity. When it happens after the user has had the app in background for an extensive amount of time (6h to 20 days) then The MAUI App.cs still remembers the MainPage that was used last time, and does not reconstruct none oof the pages in current navigation stack. Is this intended and if it is, does this mean we need to manually restart all the platform dependent code when new Activity is created?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants