Search code examples
c#windows-phone-8isolatedstorage

Store Reminder in IsolatedStorageSettings.ApplicationSettings


I am trying to store a Reminder in the IsolatedStorage. It works at runtime but if I restart the app all data is gone.

Here some code to make fun about:

private IsolatedStorageSettings userSettings = IsolatedStorageSettings.ApplicationSettings;

private List<ScheduledAction> getStorage()
{
    if (!userSettings.Contains("notifications"))
    {
        userSettings.Add("notifications", new List<ScheduledAction>());
    }

    return (List<ScheduledAction>)userSettings["notifications"];
}
private void saveStorage(List<ScheduledAction> list)
{
    userSettings["notifications"] = list;
}

private void test()
{
    List<ScheduledAction> list = getStorage();
    Reminder alarm = new Reminder("name");
    list.Add(alarm);
    saveStorage(list);
}

My current guess why the object is not stored is that Reminder is not serializable. Since this is not my object what can I do about that?


Solution

  • Whenever we add or update in IsolatedStorageSettings.Save Method , need to save before application exit. I made little changes in your code, may this will help you.

    private List<ScheduledAction> getStorage()
    {
        if (!userSettings.Contains("notifications"))
        {
            userSettings.Add("notifications", new List<ScheduledAction>());
           userSettings.Save();
        }
    
        return (List<ScheduledAction>)userSettings["notifications"];
    }
    
    private void saveStorage(List<ScheduledAction> list)
    {
        userSettings["notifications"] = list;
        userSettings.Save();
    }