Force Sign In when app is returned to from background


  • I am building a Universal app for Windows Phone 8.1 and Windows 8.1. 

    If you're familiar with these new application life cycles the apps do not suspend.  Strangely, the app continues running, even in VS2013 the OnSuspending method is never called.  If you back out of the app, manually shut the app down by holding back, or even let the app just fall off by opening a series of other apps.  The app never calls OnSuspending.  The only time it get's called is with Windows 8.1 (not Windows Phone 8.1) when you hide the app and then restart the app by choosing the app tile.  This suspends the already lost running app and starts a new app with the suspended state.  Anyway, I'm leaving topic... My point is I don't know how to capture the app hiding or being left. 

    The reason:  I need to be able to request the user to sign back in every time they leave the app and then return to it.  For example:  If I push the windows button (either device) my app hides.  I can navigate back to the app or press the tile to go back to the app.  When I do this the app is always back to where it left off.  I need a way to capture this so that I can force users to sign back in on restart.  I know it doesn't sound fair but for what I'm doing I need this action.

    Can anyone guide me into a method on how to do this without writing a lot of my own logic.  I know I can figure it out with a timer or something but what I'm looking for is that maybe I'm overlooking something obvious for a better way.

    Love, praise, and worship God :)

    Saturday, August 30, 2014 5:27 AM


  • Visual Studio disables suspension when debugging, so you'll never see real suspend events in the debugger. You can synthesise suspend and resume events from VS's toolbars. Outside of the debugger you should get suspended shortly after switching to another app. The app won't suspend when the user goes to the Start Screen, but should if the picks a different app.

    If you want to block more aggressively than suspension you can subscribe to the CoreWindow.Activated event, but you'll have to check for switching to other windows (e.g. the settings pane) within the same app.

    Saturday, August 30, 2014 3:09 PM