Reputation: 3180
My app uses a timer that vibrates the device. Now I want to stop this timer when the call is received, otherwise the device goes on vibrating during the call also, and start it back again when the call ends. I tried to handle the events Obscured and Unobscured
PhoneApplicationFrame rootFrame = App.Current.RootVisual as PhoneApplicationFrame;
if (rootFrame != null)
{
rootFrame.Obscured += new EventHandler<ObscuredEventArgs>(rootFrame_Obscured);
rootFrame.Unobscured += new EventHandler(rootFrame_Unobscured);
}
but this is not working. These events did not occur when the call was received. How should i handle this?
Upvotes: 3
Views: 1064
Reputation: 155
In App.xaml.cs, there are two methods as seen below. The first is triggered when the application is navigated to and the second is triggered when you navigate from the app (e.g. when you receive a call).
// 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
}
Upvotes: 4