我正在为金融部门构建一个Windows Phone 8应用程序。由于它包含信用卡号码等敏感信息,我需要在快速应用程序切换时设置15分钟超时,即,如果用户在15分钟内“挂起”应用程序并单击“上一步”按钮返回应用程序,它应该会恢复。如果超过15分钟,则应重定向回登录页面。
我曾尝试将OnNavigateFrom和To方法与dispatcher计时器结合使用,但这样做有两个问题。1、当应用挂起时,后台进程不运行,因此计时器停止。2、我的应用程序有多个页面,并且没有给应用程序任何警告,它即将被暂停。我无法区分在应用程序中从一个页面导航到另一个页面,还是完全离开应用程序。
那么,有没有可能在应用程序挂起的同时运行计时器?如果做不到这一点,我如何完全关闭FAS,并在每次应用程序恢复时简单地重新启动登录?我知道这违背了Windows Phone 8的一些可用性原则,但使用这款应用的金融机构有一些需要满足的要求。
有关此主题的Microsoft指南如下所示:
http://msdn.microsoft.com/en-us/library/windows/apps/hh465088.aspx
以下是此页面的摘录:
“如果距离用户上次访问已有很长一段时间,请重新启动应用程序”
但不幸的是,没有提到如何真正做到这一点...?
编辑:
多亏了crea7or的回答,我现在知道了Application_Deactivated和Application_Activated方法。我已经在独立存储中保存了时间,并在Actived方法中进行了比较。我已经尝试了以下两种解决方案。在这个例子中,什么都没有发生(没有错误但没有效果):
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根据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但这在Uri类型转换上失败。有什么想法...?
发布于 2014-01-06 20:31:09
将Application_Deactivated中的时间保存到IsolatedStorageSettings中,并显式调用Save()。读取Application_Activated上的时间,如果超时,请将UriMaper替换为以下内容:
MyUriMapper myMapper = new MyUriMapper();
myMapper.forceToStartPage = true;
RootFrame.UriMapper = myMapper;
..clear the other sensitive data of your app (cards info etc.)其中:
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;
}
}https://stackoverflow.com/questions/20949709
复制相似问题