关闭应用程序之前做东西的方法?

时间:2013-02-28 19:05:30

标签: actionscript-3 flex actionscript flex4

在应用程序关闭之前有没有办法执行某些操作? 例如,有人关闭了应用程序,但在它发生之前我必须将一些数据发送到服务器......

1 个答案:

答案 0 :(得分:2)

请澄清哪个平台!!!

对于浏览器,您必须使用JavaScript onbeforeunload事件和Flash externalInterface。 Here is a how to Link!

对于Android,它看起来像这样!

if(Capabilities.cpuArchitecture=="ARM") // check if Android
{
    NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
    NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
    NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
}

private function handleActivate(event:Event):void
{
    // load your stuff again or whatever 
    NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}

private function handleDeactivate(event:Event):void
{
    // Save your Stuff and do whatever!!!
    NativeApplication.nativeApplication.exit();
}

private function handleKeys(event:KeyboardEvent):void
{
    if(event.keyCode == Keyboard.BACK){
        // Save your Stuff and do whatever!!!
        NativeApplication.nativeApplication.exit();
    }
}