问题描述
我正在使用 MVVM Light 开发 WP8.1 应用程序.默认情况下启用快速应用恢复,这很棒,因为我想将它包含在应用中.
I am developing a WP8.1 app using MVVM Light. Fast app resume is activated by default which is great as I want to include it in the app.
当从 Visual Studio 启动应用程序时,它按预期工作.但是,当应用程序直接在设备上启动时会出现问题.以下情况会导致崩溃:
It works as expected when the app is launched from visual studio. However problems arise when the app is launched directly on the device. The following scenarios result in a crash:
- 从设备开始菜单启动应用
- 退出应用程序(使用 Windows 按钮)
- 通过后退按钮或开始菜单中的图标返回应用程序.
在第 3 步,应用崩溃,没有任何错误消息.
At step 3 the app crashes without any error message.
附言我正在 Lumia 1520 上进行测试
p.s. I am testing on a Lumia 1520
最好的问候,汤姆
推荐答案
在您的 App.xaml.cs 中,添加以下代码:
In your App.xaml.cs, add this code:
private bool reset;
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
RootFrame.Navigating += RootFrame_Navigating;
RootFrame.Navigated += RootFrame_Navigated;
}
void RootFrame_Navigated(object sender, NavigationEventArgs e)
{
reset = (e.NavigationMode == NavigationMode.Reset);
}
void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (reset && e.IsCancelable && e.Uri.OriginalString == "/XXXX.xaml")
{
e.Cancel = true;
reset = false;
}
}
在您的 WMAppManifest.xml 中,添加以下代码:
And in your WMAppManifest.xml, add this code:
<Tasks>
<DefaultTask Name="_default" NavigationPage="XXXX.xaml" ActivationPolicy="Resume" />
</Tasks>
这篇关于当未连接到调试器时,快速应用程序恢复在 WP8.1 上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!