2

我正在使用 Windows Phone。当我的应用程序停用并进入后台时,我想检测 OnNavigatedFrom 事件上的应用程序停用,以便我可以在应用程序进入后台时实现一些逻辑。我怎样才能做到这一点?????

4

3 回答 3

1

我自己找到了解决方案。将处理程序附加到您从中导航的页面上的 PhoneApplicationService.Current.Deactivated 事件。

于 2013-03-04T05:33:51.820 回答
1

您可以保存从 APP 事件或页面事件中停用它的时间,并将其存储在 IsolatedStorage 中,然后在您的应用重新激活 (OnNavigatedTo) 时检索数据。

于 2013-03-04T08:10:45.847 回答
0

使用以下方法(可在 App.xaml.cs 文件中找到)在应用激活或停用时执行逻辑:

// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{

}

// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{

}

// Code to execute when the application is deactivated (sent to background)
// This code will not execute when the application is closing
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{

}

// Code to execute when the application is closing (eg, user hit Back)
// This code will not execute when the application is deactivated
private void Application_Closing(object sender, ClosingEventArgs e)
{

}
于 2013-03-04T05:24:23.057 回答