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

Properties dictionary does not persist across restarts

$
0
0

At https://developer.xamarin.com/guides/xamarin-forms/working-with/app-lifecycle/#Persistence we're told that calling await Application.Current.SavePropertiesAsync() immediately after adding a key to the Properties dictionary will save the Properties across restarts. Unfortunately, I'm not observing this behavior in my application. My code is as follows:

private async void OnServerHostNameEntryCompleted(object sender, string hostname, string successmsg, string failmsg) 
{
    try 
    {
        Application.Current.Properties["server"] = hostname;
        await Application.Current.SavePropertiesAsync ();
        Device.BeginInvokeOnMainThread (() => DisplayAlert ("Success", successmsg, "OK") );
    }
    catch (Exception ex)
    {
        Device.BeginInvokeOnMainThread (() => 
            DisplayAlert ("Failed", failmsg + " Info: " + Environment.NewLine + ex, "OK") );
    }
}

Does anyone see anything wrong with this? It never seems to save. The code that uses the server entry looks like this:

var svr = new EntryCell ();
svr.Label = "Server";
if (Application.Current.Properties.ContainsKey ("server"))
    svr.Text = Application.Current.Properties["server"] as string;
else
    svr.Text = Client.DefaultServer;

The cell always displays the value of DefaultServer after restarting the application, no matter how long I wait after setting the settings before closing my app.

Viewing all articles
Browse latest Browse all 77050

Trending Articles



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