Results 1 to 4 of 4
  1.    #1  
    I'm having trouble saving to a database when my app is closed. I have this code in my deactivate method for the scene in question:

    ViewAssistant.prototype.deactivate = function(event) {
        if(this.pages.length > 0) {
            this.stuff[this.selectedIndex].title = this.controller.get('view-title').mojo.getValue();
            this.stuff[this.selectedIndex].text = this.controller.get('view-textarea').mojo.getValue();
  'deactivate: SAVING - ' + this.stuff[this.selectedIndex].text);
        obj.UpdateDatabase(, this.stuff, function(){'UPDATE SUCCESS');}.bind(this));'deactivate: UPDATED');
    When I swipe back the Notes.Pages.UpdateDatabase method (which adds an item to a depot) logs the message 'UPDATE SUCCESS' to confirm it has finished.

    However, when I swipe the scene upwards to close it, all the above logs turn up fine, but the 'UPDATE SUCCESS' message never appears - ie. the success callback from the Depot.add method never fires - and so the new info never saves to the db.

    Is this the correct behaviour for when an app closes? And if so, is there another way of making sure the app waits for the callback from the db before closing?
    Last edited by semprance; 11/24/2010 at 02:25 PM.
  2. #2  
    You need to listen for the "stageDeactivage" event on your stageController's document object.

    Here's the code from Scratch, that listens for that exact event and then saves the active file using the cached this.EH.SaveEntry function.

    Doug Meerschaert

    Apps: Scratch, GasMath, CheckMath
  3. #3  
    Thank you so much Planesdragon!
    I've been trying to figure this out forever.
    Your post tipped me off to this online resource which explains things further...
    Mojo.Event.stageDeactivate - WebOS101
    Developer of: FFplayer - a file/folder based music player. FFplayer home
  4. #4  
    While you can perform operations in stageDeactivate (when the card is minimized), asynchronous operations (like db transactions) are not guaranteed to finish if the user minimizes the card and quickly closes it. So sometimes they may work, but other times they will not.

    You can read about some options around this limitation here:
    Quick Post: The quick way to post messages and photos to Twitter & Facebook (video link)
    Music Player (Remix): The next generation music listening experience on webOS (video link)
    GeoStrings: Set location-based reminders and never forget another task (video link)

    Twitter: @Hedami

Posting Permissions