我的应用程序使用振动设备的计时器。现在我想在接到电话时停止这个计时器,否则设备在通话过程中也会继续振动,并在通话结束时重新启动它。我试图处理 Obscured 和 Unobscured 事件

PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame;

if (rootFrame != null)
{
    rootFrame.Obscured += new EventHandler<ObscuredEventArgs>(rootFrame_Obscured);
    rootFrame.Unobscured += new EventHandler(rootFrame_Unobscured);
}

但这不起作用。接到调用时未发生这些事件。我该如何处理?

最佳答案

在 App.xaml.cs 中,有两种方法,如下所示。第一个在导航到应用程序时触发,第二个在您从应用程序导航时触发(例如,当您接到电话时)。

// 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)
{
    //start timer here
}

// 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)
{
    //stop timer here
}

关于c# - 如何在 Windows Phone 8 应用程序中处理调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20805226/

10-11 11:41