Asked by:
In metro ,how to judge the lock screen event ?

Question
-
The situation is , when the screen is locked or power off, the App should detect this status to do someting. So the question is how to judge the lock screen event? Is there some API like ACTION_SCREEN_ON and ACTION_SCREEN_OFF in android?Thank you very much.
- Edited by tatatee Wednesday, August 1, 2012 9:38 AM
Wednesday, August 1, 2012 9:30 AM
All replies
-
Anyone can help me?
Thursday, August 2, 2012 1:24 AM -
Hi T,
What would you try to do if you could get this event? Why do you need to know when the lock screen is up or when the machine is being powered off?
-Jeff
Jeff Sanders (MSFT)
Thursday, August 2, 2012 1:47 PMModerator -
Hi Jeff,
Thanks for your reply. I want to know when the screen is power off ,not the machine is power off. Because if I know this status ,I can control the metro App not to interact with the mobile device just like the wireless Router, it can save the power of the mobile device.
Friday, August 3, 2012 1:08 AM -
Hi T,
The answer is no, you cannot detect this. You do not need to however. The Operating system can and often will suspend the application whenever it is not in view. You can use this fact to ensure that it is not interacting with the router. For more on the Process Lifetime Management of an app see this:
http://msdn.microsoft.com/en-us/library/windows/apps/hh464925.aspx
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Friday, August 3, 2012 12:13 PM
Friday, August 3, 2012 12:13 PMModerator -
Hi Jeff,
Thank you very much. I have some other questions.
First, if my metro apphas a background task, when the app is suspended, whether the background task is running or suspended like the app?
Second, if the background task is running, it will post a http request frenquently, how can I judge the app has been suspended so that I can stop to post the http request to the router, and keep the network is working; if the background task is suspended too, how to keep the network is connected? Because the background task may download or upload some files even the app is suspended.
Look forward to your reply.
- Edited by tatatee Wednesday, August 8, 2012 9:09 AM modify
Wednesday, August 8, 2012 9:09 AM -
Hi Tatatee,
Start by learning about background tasks from the Whitepaper on this: http://www.microsoft.com/en-us/download/details.aspx?id=27411
Then come back with any questions you may have.
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Wednesday, August 8, 2012 12:24 PM
Wednesday, August 8, 2012 12:24 PMModerator -
Hi Jeff,
I am back, in this article I understood the difference between the foreground task and the background task. When the app is suspended, the background is running, right? But now I have a question. Because the background task query the router frequently, it will depleting the router’s battery ,so I want to detect the state or event whether the app is removed from the lockscreen or added to the lockscreen. If the app is on the lockscreen, let the background task query the router; and if the app is not in the lockscreen, stop the operation. Thank you.
- Edited by tatatee Thursday, August 9, 2012 5:46 AM
Thursday, August 9, 2012 3:59 AM -
Hi Tatatee,
When you say "whether the app is removed from the lockscreen or added to the lockscreen" are you asking about if the app is an enabled on the Lockscreen as a lockscreen app, or are you still asking if the user has locked the OS by hitting Windows Key+L for example.
-Jeff
Jeff Sanders (MSFT)
Thursday, August 9, 2012 1:05 PMModerator -
Hi Jeff,
The situation is ,when the app is suspended, the background task is running , it's OK. But when the screen is locked, I want to stop the background task. As I knew, when the screen is locked ,the background task is still running. Is there a way to stop the background task when the screen is locked?
Friday, August 10, 2012 12:58 AM -
There is no 'Lock Screen' event. You can prevent it from starting with the User Present condition though...
http://msdn.microsoft.com/en-us/library/windows/apps/xaml/Hh977056(v=win.10).aspx
(this is in XAML but applies to JavaScript too).
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Monday, August 13, 2012 1:12 PM
Monday, August 13, 2012 1:12 PMModerator -
But the UserPresent condition is only for the sign in situation, it is not what I want to find. Is there some way better?Tuesday, August 14, 2012 1:58 AM
-
No there is not.
Jeff Sanders (MSFT)
Tuesday, August 14, 2012 11:41 AMModerator