Reputation: 15296
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
Upvotes: 1
Views: 1255
Reputation: 15006
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 :)
}
}
Upvotes: 2