没有生命周期事件的物理设备上的应用程序生命周期 [英] Application life cycle on a physical device without Lifecycle Events

查看:31
本文介绍了没有生命周期事件的物理设备上的应用程序生命周期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有解决方案可以让我在物理设备上运行和测试应用程序生命周期?不使用 Visual Studio 2015 内置的生命周期事件"?我希望能够在按下设备上的物理按钮(箭头返回、Windows 图标等)后调用适当的生命周期方法作为 Suspend 和 Resume,并在可能的情况下获取有关调用此方法的消息,例如:

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.

例如我做的Android操作系统:

For example, the Android operating system when I do:

@Override
protected void onPause() {
    super.onPause();
    System.out.println("METOD: onPause" );          
}

当我在物理设备上运行应用程序时,我看到消息METHODS: OnPause".

I see message "METHODS: OnPause" when i run application on the physical device.

推荐答案

根据 UWP 应用程序生命周期 一旦用户切换到另一个应用程序,该应用程序将被暂停.但是,挂起事件不会在您切换后立即触发,因此在调用您的方法之前可能会有几秒钟的延迟.

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.

当用户将应用移至后台时,Windows 会等待几秒钟以查看用户是否会立即切换回该应用,以便快速切换.如果用户没有在此时间范围内切换回来,Windows 将挂起该应用.

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.

此外,当您附加了 Visual Studio 调试器时,不会触发该事件.

Additionally, when you have Visual Studio debugger attached the event won't be triggered.

关于使用 Visual Studio 调试的注意事项:*Visual Studio 阻止Windows 暂停附加到调试器的应用程序.这个是允许用户在应用程序的同时查看 Visual Studio 调试 UI在跑.在调试应用程序时,您可以向其发送挂起使用 Visual Studio 的事件.确保 *Debug Location 工具栏是正在显示,然后点击暂停图标.

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.

这篇关于没有生命周期事件的物理设备上的应用程序生命周期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆