How to keep application working under screenlock?
I am writing a WP7 application which requires to play music e开发者_高级运维ven when screen lock is activated. I have done the following:
PhoneApplicationService.Current.ApplicationIdleDetectionMode =
IdleDetectionMode.Disabled;
and am also implementing the events as follows :
void RootFrame_Obscured(Object sender, ObscuredEventArgs e)
{
_playunderLock = true;
}
void RootFrame_Unobscured(object sender, EventArgs e)
{
_playunderLock = false;
}
But my music still stops when the lock button is explicitly pressed!
Am I missing something?? Also when music is playing the default lock screen does not get activated now, even though I haven't called
PhoneApplicationService.Current.UserIdleDetectionMode =
IdleDetectionMode.Disabled;
This blog post may help: http://andreassaudemont.com/post/1068697622/useridledetectionmode-and-applicationidledetectionmode. If you need the application to keep running while the user isn't interacting with it (such as listening to backgorund music) then you need to disable user idle detection: PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;
but from your description it sounds like you are having the problem when the user locks the screen, which is application idle detection. So, the only thing I can think is that you are setting it too early (sounds odd I know!). In RunKeeper we disable application idle detection(*) in the InitializePhoneApplication method in App.xaml.cs.
(*) NOTE: Disabling idle detection of any type is any action that requires permission from the user, so you'll need to add this into your application, too.
精彩评论