Exit you application AIR for ANDROID


/ Published in: ActionScript 3
Save to your folder(s)

For your Air for Android application to properly close you need to define some handlers and respond to them.


Copy this code and paste it in your HTML
  1. // Check if we are on a Android / iPhoney device.
  2. if(Capabilities.cpuArchitecture=="ARM")
  3. {
  4. NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, handleActivate, false, 0, true);
  5. NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, handleDeactivate, false, 0, true);
  6. NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);
  7. }
  8.  
  9. private function handleActivate(event:Event):void
  10. {
  11. NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
  12. }
  13.  
  14. private function handleDeactivate(event:Event):void
  15. {
  16. NativeApplication.nativeApplication.exit();
  17. }
  18.  
  19. private function handleKeys(event:KeyboardEvent):void
  20. {
  21. if(event.keyCode == Keyboard.BACK)
  22. NativeApplication.nativeApplication.exit();
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.