Windows Phone 8 - Disable Fast App Switching (FAS) after 15 minutes

210 views Asked by At

I am building a Windows Phone 8 app for the financial sector. As it contains sensitive information such as credit card numbers, I need a 15 minute timeout on the Fast App Switching, i.e. if a user "suspends" the app and hits the Back button to get back to it within 15 minutes, it should resume. If longer than 15 minutes, it should redirect back to the login page.

I have tried using the OnNavigateFrom and To methods in conjunction with dispatcher timers, but there are 2 problems with this. 1, background processes don't run when the app is suspended, so the timer stops. 2, my app has multiple pages, and there's no warning given to the app that it's about to be suspended. I can't differentiate between navigating from page to page within the app, and navigating away from the app completely.

So, is it possible to have a timer running while the app is suspended? Failing that, how do I turn off FAS completely and simply restart the login every time the app is resumed? I know this goes against some of the Windows Phone 8 usability ethos, but the financial institutions who will use this app have certain requirements which need to be met.

The Microsoft guidelines on this subject are here:

http://msdn.microsoft.com/en-us/library/windows/apps/hh465088.aspx

Here is an excerpt from this page:

"Start the app fresh if a long period of time has elapsed since the user last accessed it"

but unfortunately there's no mention of how to actually do it...?

EDIT:

Thanks to crea7or's answer I now know about the Application_Deactivated and Application_Activated methods. I have saved the time in Isolated Storage and do a comparison in the Actived method. I have tried the following 2 solutions. In this one, nothing happens (no error but no effect):

Private Sub Application_Activated(ByVal sender As Object, ByVal e As ActivatedEventArgs)
        'Get the saved time
        Dim settings As IsolatedStorageSettings = IsolatedStorageSettings.ApplicationSettings
        Dim stime As DateTime = settings("CurrentTime")
        Dim now As DateTime = System.DateTime.Now

        If now > stime.AddSeconds(5) Then
            Dim myMapper As New MyUriMapper()
            myMapper.forceToStartPage = True
            RootFrame.UriMapper = myMapper

        End If
End Sub

I also tried this, according to the answer in this question:

 Private Sub Application_Activated(ByVal sender As Object, ByVal e As ActivatedEventArgs)
        'Get the saved time
        Dim settings As IsolatedStorageSettings = IsolatedStorageSettings.ApplicationSettings
        Dim stime As DateTime = settings("CurrentTime")
        Dim now As DateTime = System.DateTime.Now

        If now > stime.AddSeconds(5) Then
            DirectCast(App.RootFrame.UriMapper, UriMapper).UriMappings(0).MappedUri = New Uri("/MainPage.xaml", UriKind.Relative)
            App.RootFrame.Navigate(New Uri("/MainPage.xaml?dummy=1", UriKind.Relative))
            App.RootFrame.RemoveBackEntry()

        End If
Ens Sub

But that fails on the Uri cast. Any ideas...?

1

There are 1 answers

1
crea7or On

Save time in Application_Deactivated into IsolatedStorageSettings and call Save() explicitly. Read the time on Application_Activated and if timeout reached, replace UriMaper to something like this:

MyUriMapper myMapper = new MyUriMapper();
myMapper.forceToStartPage = true;
RootFrame.UriMapper = myMapper;

..clear the other sensitive data of your app (cards info etc.)

where:

public class MyUriMapper : UriMapperBase
{
    public bool forceToStartPage { get; set; }

    public override Uri MapUri( Uri uri )
    {
        if ( forceToStartPage )
        {
            forceToStartPage = false;
            uri = new Uri( "/Login.xaml", UriKind.Relative );
        }
        return uri;
    }
}