简体   繁体   中英

How can I detect the screen is locked/unlocked in Windows Phone 8.1?

I want to dispose camera and other resources when user locks the screen while using the app. Also want to reinitialize it when it's unlocked. My initial search gave me these results, which are for Windows Phone 8. How can I do same for Windows Phone 8.1?

Please note, I don't want to prevent the screen to get locked. I just want to know which event is raised when screen is locked/unlocked.

Windows Phone 8 detect screen unlock

ApplicationIdleDetectionMode for windows phone 8.1?

Idle detection for Windows Phone 8

You can subscribe to Window.Current.VisibilityChanged:

Window.Current.VisibilityChanged += CurrentWindow_VisibilityChanged;

and then do:

private async void CurrentWindow_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e)
{
    if (e.Visible)
    {
        // window visible... 
    }
    else
    {
        // window not visible, dispose and do what else needs to be done :)
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM