Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows 8 SDK (C#) Application_Deactivated and Application_Closing
    primarykey
    data
    text
    <p>I have a settings class. This class Gets and Sets values from the IsolatedStorages</p> <pre><code> public Settings() { try { // Get the settings for this application. settings = IsolatedStorageSettings.ApplicationSettings; } catch (Exception e) { Debug.WriteLine("Exception while using IsolatedStorageSettings: " + e.ToString()); } } public int CookieCountSetting { get { return GetValueOrDefault&lt;int&gt;(CookieCountSettingKeyName, CookieCountSettingDefault); } set { if (AddOrUpdateValue(CookieCountSettingKeyName, value)) { Save(); } } } public bool AddOrUpdateValue(string Key, Object value) { bool valueChanged = false; // If the key exists if (settings.Contains(Key)) { // If the value has changed if (settings[Key] != value) { // Store the new value settings[Key] = value; valueChanged = true; } } // Otherwise create the key. else { settings.Add(Key, value); valueChanged = true; } return valueChanged; } public valueType GetValueOrDefault&lt;valueType&gt;(string Key, valueType defaultValue) { valueType value; // If the key exists, retrieve the value. if (settings.Contains(Key)) { value = (valueType)settings[Key]; } // Otherwise, use the default value. else { value = defaultValue; } return value; } </code></pre> <p>// I have the save function too and some other non relevant code</p> <p>Now in my code I use this class, and set a variable from the storage</p> <pre><code> private Settings settings = new Settings(); public int CookieCount; public Game() { InitializeComponent(); CookieCount = settings.CookieCountSetting; </code></pre> <p>Eventually I want to store this value when the App closes/exits. I use this code for it</p> <pre><code> // Code to execute when the application is deactivated (sent to background) // This code will not execute when the application is closing private void Application_Deactivated(object sender, DeactivatedEventArgs e) { settings.CookieCountSetting = CookieCount; } // Code to execute when the application is closing (eg, user hit Back) // This code will not execute when the application is deactivated private void Application_Closing(object sender, ClosingEventArgs e) { settings.CookieCountSetting = CookieCount; } </code></pre> <p>My problem is that when I close the App, and start it again, the value is back to its default value.</p> <p>I see no way why this is the fact.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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