Flex mobile applications running in the background

When writing mobile applications over Flex 4.5.1, your application may be running in the background, even when pressing the back or home buttons on your device. This may become a problem if your application is doing things using timers, making server calls etc.

You can listen for Event.DEACTIVATE and Event.Activate events and stop or restart whatever is running in the background if you need to.

You do this over the NativeApplication, like:

1 NativeApplication.nativeApplication.addEventListener(Event.DEACTIVATE, appExitingHandler, false, 0, true);
2 NativeApplication.nativeApplication.addEventListener(Event.ACTIVATE, appinvokeHandler, false, 0, true);
3 NativeApplication.nativeApplication.addEventListener(KeyboardEvent.KEY_DOWN, handleKeys, false, 0, true);

In the handleKeys function you can check if the keyCode == Keyboard.BACK.

If you wish to exit the application in these situations, you can also use NativeApplication.nativeApplication.exit();


One Response to Flex mobile applications running in the background

  1. Todd says:

    I am wondering – how do you get a flex mobile app to run in the background? I have developed an app to monitor my servers, and I would like to have it running all the time on my droid phone or tablet. Is there anything you tell me about doing that with flex? Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: