8

Do anyone know, how to prevent the lockscreen in a Windows (Phone) 8.1 Universal App?

In Windows Phone 8, I have used:

PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;

Has anyone an idea?

Matt126
  • 997
  • 11
  • 25

2 Answers2

17

Code for copy-paste :)

Windows.System.Display.DisplayRequest KeepScreenOnRequest = new Windows.System.Display.DisplayRequest();

KeepScreenOnRequest.RequestActive();
RelativeGames
  • 1,593
  • 2
  • 18
  • 27
  • 2
    Up vote first. Though it is obvious, I'd still like to point out it would not work if these two statements were put in a method because KeepScreenOnRequest will be collected by GC after going out of scope. – Hong Mar 25 '15 at 20:17
  • 1
    GC usually happens when its reference count reaches 0, not when going out of scope. And of course you need to put it in a method, where else ? :) – RelativeGames Apr 02 '15 at 07:38
  • 1
    Once the method is executed, the reference to KeepScreenOnRequest drops to zero because it is a local variable declared in the method. – Hong Apr 02 '15 at 13:15
  • @Hong Wouldn't realize that, but yeah, makes sense. It might be worth to edit the answer and append this information. – RReverser Feb 15 '16 at 12:36
5

You may have a look at this question at MSDN, which points to this answer on SO. In short while using WinRT you can use DisplayRequest class:

Apps that show video or run for extended periods without user input can request that the display remain on by calling DisplayRequest::RequestActive. When a display request is activated, the device's display remains on while the app is visible. When the user moves the app out of the foreground, the system deactivates the app's display requests and reactivates them when the app returns to the foreground.

There is an example at MSDN, also remember to follow guidelines and release DisplayRequests when they are no longer needed.

Community
  • 1
  • 1
Romasz
  • 29,662
  • 13
  • 79
  • 154