Application.Current Null exception in Xamarin.Forms

In the Xamarin.Forms application, I use Application.Current.Properties to save the settings. When my LoginPage downloads, I want to see if the settings exist, but I get an exception, because Application.Current is Null. This is the (sanitized) code that is in LoginPage:

 private bool AuthTokenExists()
        {
            // The following line throws the exception
            if (Application.Current.Properties.ContainsKey("First") && Application.Current.Properties.ContainsKey("Second"))
            {
                if (Application.Current.Properties["First"] as string != null &&
                    Application.Current.Properties["Second"] as string != null)
                return true;
            }
            else
            {
            return false;
            }
        }

I read, you cannot call Application.Current.Properties in the App constructor, but this is in ContentPage. Any thoughts why I get an exception? Thanks in advance!

+4
source share
2 answers

( :-) Xamarin-VS, - . bugzilla. RunTime ( ) ( , XF-). , (, Android- SM-T900), ( :-) XF- , ( ).

, , :
- , ( )
- -
-
-
- , (, DisplayAlert Property)

, BugZilla.

, ...

+1

null, LoadApplication() .

wirte LoadApplication( new App() ); MainActivity.cs, App PCL Shaired Applciation, .

( , ), Null.

+1

All Articles