开发者

Unexpected behavior with Isolated Storage on WP7

I am getting some unexpected behavior using Isolated Storage. In this case, I am using it to maintain state for the purpose of tombstoning.

This is a Ham Radio licensing exam practice app. Here is what happens. When the app is first run, the user is on the MainPage, and selects one of two links, OptionPage1 or OptionPage2 (they work similarly so I'll just focus on one). On OptionsPage1, the user selects from a number of options, then clicks a Launch button to go to ExamPage, where the user answers the questions. Upon completion of the exam, the user goes to ScorePage to see the score. When finished with this, one of the options is to click a button to go back to the MainPage.

Each time the user chooses some action, a file in isolated storage is updated using static methods in an isolated storage handling class library. I have observed a really odd behavior. When ScorePage saves its state when the user clicks to go back to MainPage, it stores location as "MainPage" because that's where the user will be in the next millisecond. However, when MainPage reads the isolated storage file that was ju开发者_开发技巧st saved by ScorePage, it does not have the same contents that ScorePage saved! It has the contents that were saved by OptionPage1 !! I know ScorePage is saving the info correctly because I tried reading it immediately after it saved it and it was OK.

It almost looks like there might be different versions of the file being created and updated. But this makes no sense. Each Page is using the exact same static methods to save and update the isolated storage file, and there's only one folder and filename. I am very perplexed.


Cyberherbalist, I'm not sure if your using this (I'm assuming you are or your app would run into some serious issues with navigation) there is a gotcha when working with the Non-Linear Navigation Service. Basically if your saving to the file using the event handlers OnNavigatedTo or in some cases OnNavigatedFrom your writing on top of your previously saved content. In other words all the service is doing is calling the GoBack() method in which case your firing the method to save to the file again.

Heres how it works:

HomePage --> OptionsPage --> ExamPage --> ScorePage

Now when you navigate back to the home page, this is really whats happening:

HomePage <-- OptionsPage <-- ExamPage <-- ScorePage

If this is the case, create a global variable in the App.xaml.cs file that stores whether or not an exam was taken and finished. Then go to any pages your saving content and check with an "if" statement to determine whether your going to the next page in the process or your navigating back to the home page. Also make sure after you save to file on the ScorePage that you set the global variable that an exam was finished.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜