Adobe Flex Mobile: Detecting View and Orientation Change with Event Listeners

There will be a time when you want to have more control over the transitions between Adobe Flex Views, or detecting when the device orientation changes. For example, I recently built an app that had some event listeners that stayed persistent even when the user changed views. So, I needed to listen for the change event when using tabbed view navigator <s:TabbedViewNavigatorApplication/> so I could remove those event listeners and I did it like this:

this.addEventListener(Event.REMOVED_FROM_STAGE,tabChangeHandler);

I also had a need to detect when the phone was tilted. Yeh, in a perfect world everything in the app’s user interface would automatically adjust to the new state, but that isn’t always the case especially when building more complex apps. What I did was listen for orientation changes like this:

stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE,stageOrientationChangeHandler);

Even if you are using some other Flex methodology for your mobile app, hopefully these examples will give you some ideas!

Running Android Apps Using External Storage (SD Card)

Hidden in the depths of the Android docs is an important chapter about info you need to know for running your apps off an external storage card. Here’s the link if you are a developer where you can use Manifest file settings so that anytime your app is installed it will be enabled for use on your SD Card: https://developer.android.com/guide/appendix/install-location.html . If you aren’t a developer then I can’t help you much because these settings require access to either the application source code, or the Android Debug Bridge.

You can also enable your apps for external storage from the adb command line using adb shell pm setInstallLocation 2. See the screenshot below. Once you’ve done that then use the adb install /mydir/some.apk to push the app to the phone. If the app isn’t automatically pushed to the card, then you’ll have to go into your droids application manager, select your application name, and then select “Move to SD”.

If you move the app to the external card you can find it using the built-in Android file browser under /mnt/asec/…

Here’s a quick link to Android dev docs on writing to internal and external storage. And, should you so desire to create a database on an external card you would point the SQLiteDatabase.openDatabase method to the appropriate directory path. I’ll point out that external storage is inherently insecure and you wouldn’t want to store passwords or anything important on it.

I’ll also add that not all storage cards are equal and some are much, much slower than others. Do your research, especially if you have a large application and you want snappy startup or read/write performance.

Presenting at the Esri Developer Summit

I’ll be presenting at the Esri Developer Summit this week (March 7 – 9, 2011) . So, if you are at the conference in Palm Springs, California stop by and say “hi”. If you aren’t familiar with this conference, it is the largest geo-developer conference in North America with over 1200 geo-geeks basking in all manner of technical geographic goodness. There will be 63 technical sessions and around 29 sessions presented by non-Esri, ArcGIS developers. What better way to learn than to hear it straight from the developers on the front lines…right??!

I have three sessions: a pre-conference session on Getting Started with the ArcGIS API for Android (beta), Localizing the ArcGIS Viewer for Flex, and integrated Volunteered Geographic Information and Social Media into your GIS. A GIS, is a Geographic Information System, for all you non-geo-geeks. Hope to see you there!