locked
Hello World Application - State Issue

    Question

  • I created the Hello World application for the Windows Store and everything worked correctly, up to where the state management was implemented for the Photo page.  All of the code is there but it does not seem to work as I think it should.  My expectation is that the session management logic should enable me to suspend or shutdown the application; then resume and the image would still be there.

    What I am experiencing is that when the LoadState method is executed the pageState parameter is null.  Thus, nothing is ever loaded. I have verified that when SaveState runs it does store the mruToken.

    The documentation I am following is found here http://msdn.microsoft.com/en-us/library/windows/apps/jj655411.aspx.  My guess is that I am just missing something about how the state management in Windows 8 store apps work.

    Monday, February 18, 2013 4:52 AM

Answers

  • Are you running your app under the debugger? Visual Studio turns off lifetime management so the app can be debugged without suspending. This is why you have to force the suspend in Visual Studio. You shouldn't need to do so when running it normally. Outside of the debugger the app should suspend several seconds after you switch away from it.

    Note that if the user explicitly closes the app then it may not have a chance to suspend and state may be lost. In general you should save state such as which page the user is on when suspending. Actual data changes should be saved more often: either as they occur, when the user navigates, when visibility changes, etc.

    --Rob

    Monday, February 18, 2013 11:06 PM
    Owner

All replies

  • Have you checked out the LayoutAwarePage class in the Grid Application Template. It implements State Management pretty well. You should diff your approach with that.

    Dev@Mic

    Monday, February 18, 2013 6:08 AM
  • That is the base class that is already used by the demo to manage state.  After researching this more I think my real issue is that I do not understand the scenarios where state should be saved.  What I have found is that if I force a "Suspend and Shutdown" in Visual Studio the state is saved and if I attempt to open my application up again it restores to the photo page.  However, I can not seem to make this happen with any other means.

    Based on what I can tell now, the demo may not really be built to do what I expected.  I had thought that if I were to open up the application, then show an image, and finally close the application; it should restore to the same point with the photo page and my selected photo.  I don't think this was ever the intention of the design of the example.

    If this is correct, I am left with the following question.  In what real world scenario should the save and load work for the photo page.

    Eddie

    Monday, February 18, 2013 10:36 PM
  • Are you running your app under the debugger? Visual Studio turns off lifetime management so the app can be debugged without suspending. This is why you have to force the suspend in Visual Studio. You shouldn't need to do so when running it normally. Outside of the debugger the app should suspend several seconds after you switch away from it.

    Note that if the user explicitly closes the app then it may not have a chance to suspend and state may be lost. In general you should save state such as which page the user is on when suspending. Actual data changes should be saved more often: either as they occur, when the user navigates, when visibility changes, etc.

    --Rob

    Monday, February 18, 2013 11:06 PM
    Owner