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

App Lifecycle event OnResume called more than once. #7894

Closed
1 task done
GeorgeLeithead opened this issue Jun 9, 2022 · 7 comments · Fixed by #14152
Closed
1 task done

App Lifecycle event OnResume called more than once. #7894

GeorgeLeithead opened this issue Jun 9, 2022 · 7 comments · Fixed by #14152
Labels
area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! partner/winui WinUI / Project Reunion platform/windows 🪟 t/bug Something isn't working

Comments

@GeorgeLeithead
Copy link

GeorgeLeithead commented Jun 9, 2022

Description

The application lifecycle event OnResume is called more than once when an application is minimised/stopped and then resumed.

image

image

Steps to Reproduce

  1. Create a new project using the ".NET MAUI App" template.
  2. Edit App.xaml.cs
  3. Add within the partial class the following:
	private int ResumeCount = 0;
  1. Add an override method for OnResume:
	protected override void OnResume()
	{
		base.OnResume();
		ResumeCount++;
		System.Diagnostics.Debug.WriteLine("{0}: Restarted {1}", DateTimeOffset.UtcNow, ResumeCount);
	}
  1. Build and launch in debug (Windows Machine):
  2. Minimise the app
  3. Restore the app
  4. In the debug output window, there will be 2 debug statements indicating:
    Restarted 1
    Restarted 2

Version with bug

6.0 (current)

Last version that worked well

Unknown/Other

Affected platforms

Windows, I was not able test on other platforms

Affected platform versions

Android 21.0, Windows 10.0.17763.0

Did you find any workaround?

No response

Relevant log output

09/06/2022 13:29:24 +00:00: Restarted 1
09/06/2022 13:29:24 +00:00: Restarted 2

VS bug #1778056

Depends on

@GeorgeLeithead GeorgeLeithead added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jun 9, 2022
@jfversluis jfversluis added area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Jun 9, 2022
@GeorgeLeithead
Copy link
Author

Just checked for Android API 31 (Pixel 5), by changing the target for debug, and it doesn't appear to occur. To confirm I also debugged on the OOTB 'VisualStudio_android-25_x86_phone (Android 7.1 - API 25)" emulator, and it does not occur on this either.
As such I can confirm that the issue occurs on the "Windows Machine" and NOT Android emulators. I do not have any other platforms (iOS or MAC) to be able to verify these.

@GeorgeLeithead
Copy link
Author

I have checked the Platforms, specifically for the Windows platform, and any additional builder wire-ups, and there is nothing that I can find that the default template provides that could account for multiple invokes.

@GeorgeLeithead
Copy link
Author

I have additionally added OnSleep and OnStart, to determine if these are invoked more than once also. I can confirm that on both "Windows Machine" and "Android Emulator" that OnSleep and OnStart are correctly invoked 1 time.

Code used:

public partial class App : Application
{
	private int ResumeCount, SleepCount, StartCount = 0;

	public App()
	{
		InitializeComponent();

		MainPage = new AppShell();
	}

	/// <summary>Perform actions when the application resumes from a sleeping state.</summary>
	protected override void OnResume()
	{
		base.OnResume();
		ResumeCount++;
		System.Diagnostics.Debug.WriteLine("{0}: Restarted {1}", DateTimeOffset.UtcNow, ResumeCount);
	}

	protected override void OnSleep()
	{
		base.OnSleep();
		SleepCount++;
		System.Diagnostics.Debug.WriteLine("{0}: Gone to sleep {1}", DateTimeOffset.UtcNow, SleepCount);
	}

	protected override void OnStart()
	{
		base.OnStart();
		StartCount++;
		System.Diagnostics.Debug.WriteLine("{0}: Started {1}", DateTimeOffset.UtcNow, StartCount);
	}
}

@PureWeen PureWeen self-assigned this Jun 10, 2022
@PureWeen PureWeen added this to the 6.0-sr2 milestone Jun 10, 2022
@GeorgeLeithead
Copy link
Author

I have created a repository and added in platform life-cycle event logging in addition to the cross-platform lift-cycle logging.

You can find it here: PlatformLifeCycleDemo on GitHub

The big takeaway for logging is below and on the repository:
When the Windows Machine is used in debug, the following events occur, and the second onResume should not occur:

LifeCycleEvent: Life-cycle event: OnLaunching
LifeCycleEvent: Life-cycle event: OnPlatformMessage (70)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (124)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (125)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (124)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (125)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (70)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (131)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (71)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (128)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (128)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (12)
CrossPlatformLifeCycleEvent: Cross-platform life-cycle event: OnStart : 1
LifeCycleEvent: Life-cycle event: OnWindowCreated
LifeCycleEvent: Life-cycle event: OnPlatformMessage (24)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (70)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (70)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (28)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (134)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (127)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (6)
LifeCycleEvent: Life-cycle event: OnActivated
LifeCycleEvent: Life-cycle event: OnPlatformMessage (127)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (36)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (15)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (133)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (20)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (127)
LifeCycleEvent: Life-cycle event: OnVisibilityChanged:True
LifeCycleEvent: Life-cycle event: OnPlatformMessage (71)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (5)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (3)
LifeCycleEvent: Life-cycle event: OnLaunched
LifeCycleEvent: Life-cycle event: OnPlatformMessage (799)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (49374)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (20)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (20)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (15)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (13)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (528)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (33)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (274)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (70)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (36)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (131)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (71)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (3)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (5)
CrossPlatformLifeCycleEvent: Cross-platform life-cycle event: OnSleep : 1
LifeCycleEvent: Life-cycle event: OnVisibilityChanged:False
LifeCycleEvent: Life-cycle event: OnPlatformMessage (134)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (6)
LifeCycleEvent: Life-cycle event: OnActivated
LifeCycleEvent: Life-cycle event: OnPlatformMessage (28)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (127)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (127)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (70)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (71)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (28)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (134)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (6)
CrossPlatformLifeCycleEvent: Cross-platform life-cycle event: OnResume : 1
LifeCycleEvent: Life-cycle event: OnResumed
LifeCycleEvent: Life-cycle event: OnActivated
LifeCycleEvent: Life-cycle event: OnPlatformMessage (274)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (19)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (70)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (36)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (131)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (133)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (20)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (71)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (3)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (5)
LifeCycleEvent: Life-cycle event: OnVisibilityChanged:True
LifeCycleEvent: Life-cycle event: OnPlatformMessage (641)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (642)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (61)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (61)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (7)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (6)
CrossPlatformLifeCycleEvent: Cross-platform life-cycle event: OnResume : 2
LifeCycleEvent: Life-cycle event: OnResumed
LifeCycleEvent: Life-cycle event: OnActivated
LifeCycleEvent: Life-cycle event: OnPlatformMessage (8)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (641)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (15)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (528)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (33)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (32)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (274)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (16)
LifeCycleEvent: Life-cycle event: OnClosed
CrossPlatformLifeCycleEvent: Cross-platform life-cycle event: OnSleep : 1
LifeCycleEvent: Life-cycle event: OnVisibilityChanged:False
LifeCycleEvent: Life-cycle event: OnPlatformMessage (528)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (20)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (641)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (61)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (61)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (7)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (144)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (70)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (71)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (134)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (6)
LifeCycleEvent: Life-cycle event: OnActivated
LifeCycleEvent: Life-cycle event: OnPlatformMessage (28)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (8)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (641)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (642)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (2)
LifeCycleEvent: Life-cycle event: OnPlatformMessage (130)

Then the Android Emulator is used in debug, the following events occur:

[0:] LifeCycleEvent: Life-cycle event: OnApplicationCreating
[0:] LifeCycleEvent: Life-cycle event: OnApplicationCreate
[0:] LifeCycleEvent: Life-cycle event: OnCreate
[0:] LifeCycleEvent: Life-cycle event: OnStart
[0:] CrossPlatformLifeCycleEvent: Cross-platform life-cycle event: OnStart : 1
[0:] LifeCycleEvent: Life-cycle event: OnPostCreate
[0:] LifeCycleEvent: Life-cycle event: OnResume
[0:] LifeCycleEvent: Life-cycle event: OnPostResume
[0:] LifeCycleEvent: Life-cycle event: OnPause
[0:] CrossPlatformLifeCycleEvent: Cross-platform life-cycle event: OnSleep : 1
[0:] LifeCycleEvent: Life-cycle event: OnStop
[0:] LifeCycleEvent: Life-cycle event: OnSaveInstanceState (Bundle[{android:viewHierarchyState=Bundle[{android:views={1=android.view.AbsSavedState$1@2de8efa, 16908290=android.view.AbsSavedState$1@2de8efa, 2131230775=android.view.AbsSavedState$1@2de8efa, 2131230786=android.view.AbsSavedState$1@2de8efa}}], android:lastAutofillId=1073741823, android:fragments=android.app.FragmentManagerState@7af3cab}])
[0:] LifeCycleEvent: Life-cycle event: OnApplicationTrimMemory (UiHidden)
[0:] CrossPlatformLifeCycleEvent: Cross-platform life-cycle event: OnResume : 1
[0:] LifeCycleEvent: Life-cycle event: OnRestart
[0:] LifeCycleEvent: Life-cycle event: OnStart
[0:] LifeCycleEvent: Life-cycle event: OnResume
[0:] LifeCycleEvent: Life-cycle event: OnPostResume

@GeorgeLeithead
Copy link
Author

Not to say for sure, but I think it's the OnVisibilityChanged platform event being called after the OnResumed and onActivated events, which is invoking the cross-platform OnResume event the second time.

@hartez hartez modified the milestones: 6.0-sr2, 6.0-sr3 Jun 27, 2022
@PureWeen
Copy link
Member

PureWeen commented Jul 5, 2022

AFAICT this is a bug with the WinAppSdk firing the OnActivated event twice

microsoft/microsoft-ui-xaml#7343

@PureWeen PureWeen removed their assignment Aug 3, 2022
@mattleibow mattleibow modified the milestones: 6.0-sr3, 6.0-servicing Aug 29, 2022
@Redth Redth modified the milestones: 6.0-servicing, Backlog Aug 30, 2022
@ghost
Copy link

ghost commented Aug 30, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@samhouts samhouts added this to the .NET 8 milestone May 24, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jun 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-core-lifecycle XPlat and Native UIApplicationDelegate/Activity/Window lifecycle events fixed-in-8.0.0-preview.3.8149 Look for this fix in 8.0.0-preview.3.8149! partner/winui WinUI / Project Reunion platform/windows 🪟 t/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants