Online Book Reader

Home Category

Developing Android Applications with Adobe AIR [26]

By Root 2506 0
SocketMonitor;

import flash.net.URLRequest;

import flash.events.StatusEvent;

var monitor:URLMonitor =

new URLMonitor(new URLRequest("http://www.google.com"));

monitor.pollInterval = 1000;

monitor.addEventListener(StatusEvent.STATUS, onStatus);

monitor.start();

function onStatus(event:StatusEvent):void {

monitor.stop();

trace(event.code); // Service.available or Service.unavailable

trace(event.target.available); // true or false

Conclusion

In this chapter, we discussed what you need to do to develop for multiple devices. Schedule a reasonable amount of time up front to plan for differences and specifics. The investment will pay off when you test your application on phones and tablets and see it working as expected. This is when you will notice and enjoy the benefits of universal deployment.

This concludes the book’s introductory chapters. We will now dive into the various APIs specific to Android development.

Chapter 6. Opening and Closing an Application and Saving Data

The difference between a bad programmer and a good one is whether he considers his code or his data structures more important. Bad programmers worry about the code. Good programmers worry about data structures and their relationships.

—Linus Benedict Torvalds

In Android, every application, also called an activity, is given a unique user ID and runs in its own process. The system—more specifically, the Activity Manager—manages the life cycle of applications and provides a common activity stack.

The application life cycle has three states: active, paused, and stopped. The Activity Manager keeps track of the list of application processes currently running, in order, from newest to oldest. If memory is needed, the oldest application is terminated first. It may receive an event first or be terminated at once.

The decision is therefore very much a result of the user’s interaction and history, with the current activity being the most important. AIR applications on Android are treated as any other application, as we will see in this chapter.

While an application has a limited life cycle, it has the ability to save persistent data. Android provides an SQLite database, document-like data, as well as an internal state, which is a simple set of name/value pairs associated with an activity.

AIR uses its own APIs to save data. The AIR runtime comes with an SQLite engine and access to the filesystem. It also provides local shared objects, a cookie-like solution. We will go over all of these options.

The AIR Application


NativeApplication represents your AIR application. It belongs to the flash.desktop package and inherits from EventDispatcher. It is a singleton automatically created when the application launches. You can get a reference to it via the static property NativeApplication.nativeApplication.

NativeApplication dispatches application-specific events such as invoking and exiting and has application-specific properties such as icon and systemIdleMode. Some of its properties, created for AIR on the desktop, are not relevant to the mobile environment, such as activeWindow and openedWindows, because there are no multiple windows in this environment.

Opening the Application


When you first start your application by clicking on its icon or via another process, the previously active application moves to the background. Your application launches and comes to the foreground to occupy the home screen. Navigating between native applications or between a native application and an AIR-developed application is identical.

Android does not currently provide the option of a startup screen. You may experience a black screen while the application is setting up. Test your application and rework your initialization process if setup takes too long. As a workaround, make your root application a simple movie with a loading indicator graphic. Once it is loaded and rendered (listen for the ADDED_TO_STAGE event), load your main application in it using the Loader class. The main application .swf file must be in the list of Included Files so

Return Main Page Previous Page Next Page

®Online Book Reader