问题
Is there a solution that will allow me to run and test the application life cycle on a physical device? Without the use of "Lifecycle Events" built-in Visual Studio 2015? I wanted to be able to call the appropriate methods of life cycle as Suspend and Resume after pressing the physical buttons on the device (arrow return, windows icon, etc.) and if possible get a message about calling this method something like:
private async void Application_Suspending(object sender, SuspendingEventArgs e)
{
Debug.WriteLine("METOD: Suspending");
}
I just wanted to know which method is currently find themselves on a physical device during application testing.
For example, the Android operating system when I do:
@Override
protected void onPause() {
super.onPause();
System.out.println("METOD: onPause" );
}
I see message "METHODS: OnPause" when i run application on the physical device.
回答1:
As per the UWP Application Lifecycle the app will get suspended once the user switches to another app. However, the suspending event does not get triggered immediately after you switch, so there might be a few seconds of delay before your method is called.
When the user moves an app to the background, Windows waits a few seconds to see whether the user will immediately switch back to the app so that the transition will be fast if they do. If the user does not switch back within this time window, Windows suspends the app.
Additionally, when you have Visual Studio debugger attached the event won't be triggered.
A note about debugging using Visual Studio: *Visual Studio prevents Windows from suspending an app that is attached to the debugger. This is to allow the user to view the Visual Studio debug UI while the app is running. When you're debugging an app, you can send it a suspend event using Visual Studio. Make sure the *Debug Location toolbar is being shown, then click the Suspend icon.
来源:https://stackoverflow.com/questions/37701292/application-life-cycle-on-a-physical-device-without-lifecycle-events