Note that there are some explanatory texts on larger screens.

plurals
  1. POBest way to show a passcode screen everytime an app is launched/activated
    primarykey
    data
    text
    <p>I am working on a Windows Phone 8 App which should be protected with a passcode. What is the best way to show the passcode screen everytime the app is lauchend or activated?</p> <p>I think the central point of action shoule be the App.xaml.cs with its Launch and Activation event handlers. But how exactly can I show the passcode screen?</p> <p>The problem is, that one never know which pages will be displayed when the app launches or is reactivated. It is either the main page or any other page which was last displayed when the app was deactivated. </p> <p>I tried to intercept the navigation to the first page, cancel it and show the passcode page instead:</p> <pre><code>// App.xaml.cs private void InitializePhoneApplication() { ... RootFrame.Navigating += HandleFirstNavigation; ... } private void HandleFirstNavigation(object sender, NavigatingCancelEventArgs e) { RootFrame.Navigating -= HandleFirstNavigation; e.Cancel = true; RootFrame.Dispatcher.BeginInvoke(new Action(this.OpenPasscodePage)); } private void OpenPasscodePage() { RootFrame.Navigate(PasscodePageUri); } </code></pre> <p>This works, but only when the app lauchend. When the app reactivated (dormant or tombstoned) the e.Cancel is irgnored. Although the navigation to the passcode page is called the original page is shown.</p> <p>Moving the navigation the the passcode page from Navigating to Navigated does not worth either:</p> <pre><code>private void InitializePhoneApplication() { ... RootFrame.Navigated += PasscodePageAfterFirstNavigation; ... } private void PasscodePageAfterFirstNavigation(object sender, EventArgs e) { RootFrame.Navigated-= PasscodePageAfterFirstNavigation; RootFrame.Navigate(PasscodePageUri); } </code></pre> <p>This seems to be some kind of race condition: Sometimes the passcode page is shown, sometimes the original page. Even if the passcode pages comes up this looks bad because one first see the original page for the fraction of a second before the app navigates further to the passcode page. </p> <p>Both solution do not work. Any idea what is the right way to implement this?</p> <p><strong>EDIT:</strong> Meanwhile I tried a third solution which does not work either. This solution uses the Uri Mapper:</p> <p><strong>App.xaml.cs</strong> </p> <pre><code>public bool PasscodeWasConfirmed; private void Application_Launching(object sender, LaunchingEventArgs e) { ... PasscodeWasConfirmed = false; ... } private void Application_Activated(object sender, ActivatedEventArgs e) { ... PasscodeWasConfirmed = false; ... } public Uri InitialPageUri; public bool ShouldRedirectToPasscodePage(Uri uri) { if (PasswordWasConfirmend == false) { InitialPageUri = uri; return true; } return false; } </code></pre> <p><strong>UriMapper</strong></p> <pre><code>public class AppUriMapper : UriMapperBase { public override Uri MapUri(Uri uri) { App app = (Application.Current as App); if (app != null) { if (app.ShouldRedirectToPasscodePage(uri)) return PasscodeQueryPage.PageUri; } // default return uri; } } </code></pre> <p><strong>PasscodePage</strong></p> <pre><code>public partial class PasscodePage : PhoneApplicationPage { ... private void PasscodeConfirmed() { App app = (Application.Current as App); app.PasscodeWasConfirmed = true; NavigationService.Navigate(app.InitialPageUri); } } </code></pre> <p>The Logic is working without any problem, but the app does not navigate to InitialPageUri after the passcode was confirmed. The Uri Mapper is called and correctly and returns the InitialPageUri (no redirect any more). But no navigation happens...</p> <p>There are no errors, exceptions or debug output. simply nothing happes...</p> <p><strong>Biggest problem when using Uri Mapper:</strong> When the app is reactivated from Dormant state there is no navigation which could be mapped or redirected...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload