我的应用使用振动设备的计时器。现在我想在收到呼叫时停止此计时器,否则设备在通话期间继续振动,并在通话结束时再次启动。我试图处理隐藏和未遮挡的事件
PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame;
if (rootFrame != null)
{
rootFrame.Obscured += new EventHandler<ObscuredEventArgs>(rootFrame_Obscured);
rootFrame.Unobscured += new EventHandler(rootFrame_Unobscured);
}
但这不起作用。收到电话时没有发生这些事件。我应该怎么处理这个?
答案 0 :(得分:4)
在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
}