locked
Saving file on suspension. RRS feed

  • Question

  • Hi,

    I am planning to save all my app data (not session state, but all user entered data) incrementally whenever changes happen. And finally in my app.oncheckpoint too am going to use setpromise and save them again.   Is it enough to handle "checkpoint" alone and not "onsuspending"? Is there anyother way an app will close,that needs to be handled.

    Also, is it enough to handle all WinJS events only and believe WinRt events(onsuspending,onresuming,onsuspending) be covered automatically?


    karthika

    Friday, May 3, 2013 6:04 AM

Answers

  • It's enough to handle just the WinJS events. WinJS provides value-added wrappers for various WinRT events. The checkpoint event is such a wrapper for suspending, as WinJS uses this to save the WinJS.Application.sessionState object automatically. So you can handle one or the other, or both, as desired.

    The suspending event is the only one that comes as part of app shutdown. When a user closes an app, Windows suspends it first, then shuts it down after 10 seconds.

    In general, the events in WinJS.Application are there to consolidate events that arise from a variety of different WinRT objects, thereby making it easier to handle all those events in one place. But again, they're just value-add wrappers, not gospel. In fact, WinJS doens't wrap the resuming event because it doesn't add any value itself. But you can easily consolidate it yourself by handling the WinRT event, then using WinJS.Application.queueEvent to route it into the WinJS.Application object where you can handle it alonside checkpoint, activated, etc.

    Kraig
    Author, Programming Windows 8 Apps with HTML, CSS, and JavaScript, a free ebook from Microsoft Press

    • Marked as answer by ArunKarthika Monday, May 6, 2013 9:07 PM
    Friday, May 3, 2013 4:45 PM

All replies

  • It's enough to handle just the WinJS events. WinJS provides value-added wrappers for various WinRT events. The checkpoint event is such a wrapper for suspending, as WinJS uses this to save the WinJS.Application.sessionState object automatically. So you can handle one or the other, or both, as desired.

    The suspending event is the only one that comes as part of app shutdown. When a user closes an app, Windows suspends it first, then shuts it down after 10 seconds.

    In general, the events in WinJS.Application are there to consolidate events that arise from a variety of different WinRT objects, thereby making it easier to handle all those events in one place. But again, they're just value-add wrappers, not gospel. In fact, WinJS doens't wrap the resuming event because it doesn't add any value itself. But you can easily consolidate it yourself by handling the WinRT event, then using WinJS.Application.queueEvent to route it into the WinJS.Application object where you can handle it alonside checkpoint, activated, etc.

    Kraig
    Author, Programming Windows 8 Apps with HTML, CSS, and JavaScript, a free ebook from Microsoft Press

    • Marked as answer by ArunKarthika Monday, May 6, 2013 9:07 PM
    Friday, May 3, 2013 4:45 PM
  •    Thanks Kraig.  Now Suspension is clear, but need some help in Activation.

    I have to do 3+3 async operations(create/grab 3 files and read the data and load to array variables) inside app.addEventlistener of 'activated' handler.  Where exactly inside the  activation handler should I do these async operations?

        As stated in the ebook chapter3, How do I obtain the promise of the async operations and hand it off to setPromise? Pls can you shed some light on the code structure, where and how the async operations(create ,get and readtextAsync) need to be done. It will be of great help.

    (When I do file Async operations with then,done,  inside the WinJS.UI.processAll which is inside setPromise, the first page sometimes appears before the data is fully extracted from the file. I think I need to implement extended splashscreen as well).


    karthika

    Monday, May 6, 2013 9:15 PM