Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42642

Suspend camera when user switches away from app, and resume camera when user switches back to app

Currently, I would like to suspend my camera when user switches away from my app, and resume camera when user switches back to app

I am referring to Application lifecycle (Windows Store apps) (Windows)

However, Suspending | suspending event isn't being triggered immediately once the user switches away from my app. You need to wait for few seconds (Or it will not trigger at all if OS decides not to do so).

So, how I can know, when I should run my camera suspension code when user switches away from my app.

If I referring to Media capture using capture device sample, they are using

Windows.Media.MediaControl.SoundLevelChanged += m_soundLevelHandler;

They run camera suspension code when there is a sound level changes? But this is also not what I want. As detecting SoundLevelChanged event, is not able to let me know, whether user is switching away from my app, or switching back to my app. SoundLevelChanged event will be triggered in both scenarios.

Upvotes: 1

Views: 395

Answers (1)

MoDu
MoDu

Reputation: 106

From the MSDN article you referred.

App visibility When the user switches from your app to another app, your app is no longer visible but remains in the running state until Windows can suspend it (for about 10 seconds). If the user switches away from your app but activates or switches back to it before Windows can suspend it, the app remains in the running state. Your app doesn't receive an activation event when app visibility changes, because the app is still running. Windows simply switches to and from the app as necessary. If your app needs to do something when the user switches away and back, it can handle the VisibilityChanged | msvisibilitychange event. The visibility event is not serialized with the resume or activation events. Don't assume that these events come in a particular order.

check out the VisibilityChangedEvent

Upvotes: 2

Related Questions