Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Application.Current.Properties not persisting

$
0
0

Any data I save to Application.Current.Properties seems to clear whenever I restart the Application?

I'm using the following code to save the data:

    private static void SaveLoginLocal ()
    {
        if (Application.Current.Properties.ContainsKey ("LoggedInUser")) {
            Application.Current.Properties ["LoggedInUser"] = User.Current;
        }
        else {
            Application.Current.Properties.Add (new KeyValuePair<string, object> ("LoggedInUser", User.Current));
        }
        Application.Current.SavePropertiesAsync ();
        //LocalDB.DB.Connection.DeleteAll<User> ();
        //LocalDB.DB.Connection.Insert (User.Current);
    }

I used the Application.Current.Properties.Add (new KeyValuePair<string, object> ("LoggedInUser", User.Current)); just to test if creating a new KeyValuePair fixed the problem, but it doesn't.

From the Locals I can see that the data gets saved and I can access it for the lifetime of the application, but as soon as I close it and restart, the data gets cleared. Is this behavior expected or am I doing something wrong?

I'm using:
- Xamarin Forms V2.0.0.6490
- Android Platform
- (Checked that Preserve application data/cache is enabled) - Although I don't even have to deploy my App for the data to clear, just restart it.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>