title: (Xamarin Forms) App crash on startup (login/logout with application properties)
body: <p>I'm trying to create a login page with a login button to the matchpage, on that just a simple test button to logout. This is all fine, as in, i can login (go to matchpage page) and logout (go back to login page). I'm using the application properties to check if the user has logged in before. Appareantly this is set to the right value (i check the debug with a debug.writeline), but once i close the application (swipe away from the recent apps page on my phone) while in "IsLoggedIn" state False and try to open it again (so the loginpage should open) it either crashes or opens the "IsLoggedIn" state True page (matchpage).</p>
  
  <p>This is the App.xaml.cs</p>
  
  <pre><code>public App()
  {
      InitializeComponent();
  
      if (!Current.Properties.ContainsKey("IsLoggedIn"))
      {
          Current.Properties["IsLoggedIn"] = false;
          if ((bool)Current.Properties["IsLoggedIn"] == false)
          {
              MainPage = new LoginPage();
          }
          else
          {
              MainPage = new NavigationPage(new MatchPage());
          }
      }
      //MainPage = new NavigationPage(new MatchPage());        
  }
  </code></pre>
  
  <p>This is the LoginPage.xaml.cs</p>
  
  <pre><code>public partial class LoginPage : ContentPage
  {
      public LoginPage()
      {
          InitializeComponent();
          Debug.WriteLine((bool)Application.Current.Properties["IsLoggedIn"]);
      }
  
      private async void Button_Clicked(object sender, EventArgs e)
      {
          Application.Current.Properties["IsLoggedIn"] = true;
          await Application.Current.SavePropertiesAsync();
          Application.Current.MainPage = new NavigationPage(new MatchPage());
      }
  }
  </code></pre>
  
  <p>This is the MatchPage.xaml.cs</p>
  
  <pre><code>public partial class MatchPage : ContentPage
  {
      public MatchPage()
      {
          InitializeComponent();
          //if (!Application.Current.Properties.ContainsKey("IsLoggedIn"))
          //{
          //    if ((bool)Application.Current.Properties["IsLoggedIn"] == false)
          //    {
          //        Application.Current.MainPage = new LoginPage();
          //    }
          //}
          Debug.WriteLine((bool)Application.Current.Properties["IsLoggedIn"]);
      }
  
      private async void Button_Clicked(object sender, EventArgs e)
      {
          Application.Current.Properties["IsLoggedIn"] = false;
          await Application.Current.SavePropertiesAsync();
          Application.Current.MainPage = new LoginPage();
      }
  }
  </code></pre>
  
  <p>Hope you guys can figure out what went wrong and what I can do to fix this.</p>