In this tutorial we are going to see how to control the AutoLocking of Windows Phone Device when an application is running, or we want to disable it permanently when an application is running. This feature is a much for security where it auto locks if its idle for quite sometime, but there are some applications where the auto locking feature should be disabled on using that application. We can do that programmatically by using the PhoneApplicationServices which is available by default with the APP.XAML page which is a mandatory page loaded with the project. [more]
Let us see the steps on how to achieve this task on controlling the AutoLocking in Windows Phone. To start with Open Visual Studio 2010 IDE and create a new Silverlight for Windows Phone project with a valid project name as shown in the screen below.
Now design the page as its not in our scope we can take it granted that our application is designed and developed with the necessary controls and process and its working fine. Now go the APP.XAML Page and we can see the ApplicationLaunching Service with the list of available events as shown in the screen below.
Now let us go to the code behind App.Xaml.Cs and we can see a separate events available for each of the events on Launching, Closing, Activated and Deactivated as shown in the screen below. The name on these describes the need of these events, so lets not waste time in telling what exactly it means.
In each of the events we can write a small message to indicate which event is trigger at what time by using a message box. Now in Windows Phone we have a PhoneApplicationService class which is mainly used to maintain the application lifecycle with different options across the different phases of the cycle. It also helps to maintain the idle behavior of the application manage the applications state. PhoneApplicationService has many properties out of which we ApplicationIdleDetectionMode which is used to identify the behavior of the application. It has an enum which takes the values of Enable or Disable and as per MSDN, When application idle detection is enabled, the operating system will deactivate idle applications. Disabling application idle detection requests that the operating system not perform this service. This feature should be used with caution because applications that run while the phone is locked continue to drain the device’s battery. In this case, the user may not realize that the application is running because the screen is off and the phone looks idle. So we have added the ApplicationIdle behavior to enabled and disabled as per the event trigger as shown in the code below.
Code:
// Code to execute when the application is launching (e.g., from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
MessageBox.Show("Application Launching");
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
// 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)
{
MessageBox.Show("Application Activated");
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
}
// 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)
{
MessageBox.Show("Application Deactivated");
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Enabled;
}
// 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)
{
MessageBox.Show("Application Closing");
PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Enabled;
}
Now we are done with our code, just run the application by pressing F5 directly from the keyboard or we can use the Build and execute the project option from the tool bar to run the application. Once the Build is successful we can see the Windows Phone emulator with the application and the expected outputs as shown in the screens below.
Output Screen:
That’s it from this tutorial, hope this was quite interesting and can be used with the Application development. See you all in the next tutorial will an interesting topic on How to with Windows Phone until then Happy Programming.
No Comments
For individuals of you who are acquainted with the educational demonstrates that <b style="color:blackbackground-color:#ffff66">PBS</b> puts out for both grownups and youngsters you will be pleased to know that there is an on the web site called <b style="color:blackbackground-color:#ffff66">PBS</b> kids. This web-site provides educational <b style="color:blackbackground-color:#ffff66">PBS</b> youngsters <b style="color:blackbackground-color:#a0ffff">video games</b> and a whole whole lot additional for your kid. Right here are some usually asked issues about this site, that may possibly help you come to a decision if <b style="color:blackbackground-color:#ffff66">PBS</b> young children <b style="color:blackbackground-color:#a0ffff">games</b> are right for you.
For individuals of you who are familiar with the educational displays that <b style="color:blackbackground-color:#ffff66">PBS</b> puts out for the two grownups and little ones you will be pleased to know that there is an on the internet website known as <b style="color:blackbackground-color:#ffff66">PBS</b> little ones. This web-site provides educational <b style="color:blackbackground-color:#ffff66">PBS</b> little ones <b style="color:blackbackground-color:#a0ffff">games</b> and a total good deal much more for your kid. Here are some frequently asked concerns about this web site, that may possibly enable you choose if <b style="color:blackbackground-color:#ffff66">PBS</b> young children <b style="color:blackbackground-color:#a0ffff">games</b> are right for you.
For these of you who are familiar with the educational exhibits that <b style="color:blackbackground-color:#ffff66">PBS</b> puts out for each grownups and young children you will be pleased to know that there is an on the internet internet site known as <b style="color:blackbackground-color:#ffff66">PBS</b> youngsters. This website offers educational <b style="color:blackbackground-color:#ffff66">PBS</b> young children <b style="color:blackbackground-color:#a0ffff">games</b> and a entire lot more for your little one. Right here are some regularly asked questions about this web site, that may assist you come to a decision if <b style="color:blackbackground-color:#ffff66">PBS</b> youngsters <b style="color:blackbackground-color:#a0ffff">video games</b> are proper for you.
I love this website – its so usefull and helpfull.|
You have one of the greatest internet websites.|
Excellent Website, Keep up the useful job. Thanks a lot.|
For individuals of you who are familiar with the educational exhibits that <b style="color:blackbackground-color:#ffff66">PBS</b> puts out for both adults and youngsters you will be pleased to know that there is an on the internet web-site named <b style="color:blackbackground-color:#ffff66">PBS</b> children. This internet site offers educational <b style="color:blackbackground-color:#ffff66">PBS</b> children <b style="color:blackbackground-color:#a0ffff">games</b> and a whole great deal additional for your little one. Right here are some usually asked inquiries about this site, that may possibly assist you choose if <b style="color:blackbackground-color:#ffff66">PBS</b> kids <b style="color:blackbackground-color:#a0ffff">video games</b> are appropriate for you.
For those of you who are acquainted with the educational shows that <b style="color:blackbackground-color:#ffff66">PBS</b> puts out for both adults and little ones you will be pleased to know that there is an on-line web-site referred to as <b style="color:blackbackground-color:#ffff66">PBS</b> children. This website presents educational <b style="color:blackbackground-color:#ffff66">PBS</b> young children <b style="color:blackbackground-color:#a0ffff">games</b> and a entire whole lot a lot more for your youngster. Here are some often asked queries about this web site, that could support you choose if <b style="color:blackbackground-color:#ffff66">PBS</b> little ones <b style="color:blackbackground-color:#a0ffff">games</b> are right for you.
Wow because this is excellent work! Congrats and keep it up.
Wow because this is excellent job! Congrats and keep it up.
Great internet site! It looks very expert! Keep up the great job!
Thanks a lot. Useful stuff!
Many thanks, Useful information!
Useful data, Many thanks!
Great tips, With thanks!
Many thanks, I value this!
Wow because this is great work! Congrats and keep it up.