AS3: Exiting Android App


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

Okay, we should now have an app that quits when the user presses the Back or Home keys rather than switching to the background and eating up battery.


Copy this code and paste it in your HTML
  1. import flash.desktop.NativeApplication;
  2. import flash.events.KeyboardEvent;
  3. import flash.ui.Keyboard;
  4.  
  5. NativeApplication.nativeApplication.addEventListener( KeyboardEvent.KEY_DOWN, handleKeyDown );
  6.  
  7. function handleKeyDown( e :KeyboardEvent ) :void
  8. {
  9. switch( e.keyCode )
  10. {
  11. case Keyboard.BACK:
  12. NativeApplication.nativeApplication.exit();
  13. break;
  14.  
  15. case Keyboard.SEARCH:
  16. case Keyboard.MENU:
  17. e.preventDefault();
  18. break;
  19. }
  20. }

URL: http://mobile.tutsplus.com/tutorials/android/build-a-gps-speedometer-getting-into-air-for-android/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.