开发者

ApplicationSettings isn't saved properly

I'm trying to save two Lists of objects in the phone ApplicationSettings, but I'm stuck at a strange issue (But it's probably me making a silly mistake somewhere).

If I only save one of the lists, it works as supposed - It'll save it, and reload it when app is launched next time. But if I try to save 2 lists, none of them seem to be saved correctly. No errors or anything开发者_如何学Python, just "blankness".

See code below.

//My save method
public void Gem()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;

            if (settings.Contains(INDTASTNINGER_LIST))
            {
                settings[INDTASTNINGER_LIST] = _indtastningsListe;
            }
            else
                settings.Add(INDTASTNINGER_LIST, _indtastningsListe);

            if (settings.Contains(INDTASTNINGER_LIST2))
            {
                settings[INDTASTNINGER_LIST2] = _indtastningsListe2;
            }
            else
                settings.Add(INDTASTNINGER_LIST2, _indtastningsListe2);
            settings.Save();
        }

        //Constructor supposed to load settings
        public Indtastninger()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;

            if (settings.Contains(INDTASTNINGER_LIST))
            {
                _indtastningsListe = null;
                _indtastningsListe = (List<Indtastning>)settings[INDTASTNINGER_LIST];
            }
            if (settings.Contains(INDTASTNINGER_LIST2))
            {
                _indtastningsListe2 = null;
                _indtastningsListe2 = (List<Indtastning>)settings[INDTASTNINGER_LIST2];
            }
        }

What am I doing wrong? If I comment out the part with "list2" stuff, the first one will be saved/retrieved perfectly.


I have faced the same issue some time ago, the problem is that you only can save on the IsolatedStorage objects that are XML serializables.

if you save other object, it will work even with the debugger but when the app is restarted, all the saved data is lost.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜