Android devices generally have a set of four soft-keys along one side of the device which are always present to the user. Two of these keys involve navigation—the back and home keys. When a user activates an event such as when pressing the back button, we should consider whether it may be appropriate to fully exit the application and free up system resources for other tasks.
Note
The home button will always return the user to the Android desktop, thus deactivating our application. To see how to close an application in such an event, refer the previous recipe.
We will listen to the dedicated Android back button to be pressed and exit the application in response:
1. To begin, we will need to import the following classes into our application.
import flash.desktop.NativeApplication; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.KeyboardEvent; import flash.ui...