Posted By

chrisaiv on 11/15/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

captiv8tor


AS3: Exiting Android App


 / Published in: ActionScript 3
 

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

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.

  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. }

Report this snippet  

You need to login to post a comment.