Tombstoning in AIR-Mobile Applications



When you are building AIR-based mobile applications, you can handle Tombstoning in your application in a very elegant way. Tombstoning is a technique by which you freeze the state of your application whenever a system interrupt occurs.  For instance, when the user receives a cellular call, your application will become invisible and may get deactivated or pushed to the background. During that time, there is no point in running those game timers or animations. You can suspend all CPU/GPU intensive activities and resume all of them when the application gets activated again.

Tombstoning is an absolutely required feature that your application should support to provide a less frustrating experience to the users.

In AIR-based mobile applications, handling Tombstoning is absolutely simple.

When you are creating the mobile view, just remember to handle the view-activate and view-deactivate events:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"  
            title="HomeView" 
            viewDeactivate="handleDeactivate()" 
            viewActivate="handleActivate()">
    
    <fx:Script>
        <![CDATA[

            protected function handleDeactivate():void
            {
                   //Pause game timers
                   //Suspend animations
            }

            protected function handleActivate():void
            {
                   //Restart game timers
                   //Resume animations
            }

        ]]>
    </fx:Script>
</s:View>

You can also use these techniques to gracefully shutdown your application as the deactivate event is called on the View when the user taps the back key. Note: Tombstoning will not work if you are building AIR applications with 2.5 or lower namespace.