[How-To] Save custom data before app gets exit on Playbook

A good application should always keep current app state somewhere in case app gets crash or quite. On Playbook, when user click the red cross to close your app, you will receive Event.EXITING event and this is the place for you to do some clean up.


But if you need to a lot of stuff (eg, write to a db or even fire a webservice call), you might not have enough time to do it. Because event you call event.preventDefault(), QNX will still kill you app very quickly. One thing you can do to let QNX give you a little more time to do the clean up is to set system’s transitionTime when app launches. Just like this:

 // set system's transitionTime to 500ms  

QNXSystem.system.transitionTime = 500;

By using this code, you will have about 500ms from you get EXITING event to gets killed by QNX system. But you should also keep in mind that QNX will kill you app after 2 seconds whatever the transitionTime is set (if it’s > 2000). Here is the demo code:

 // set system's transitionTime to 500ms  

QNXSystem.system.transitionTime = 500;
NativeApplication.nativeApplication.addEventListener(Event.EXITING, onAppExisting);

protected function onAppExisting(event:Event):void
{
CONFIG::device
{
event.preventDefault();
doCleanUp();
}
}

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s