2. Mastering the Android Development Tools

Android developers are fortunate to have more than a dozen development tools at their disposal to help facilitate the design of quality applications. Understanding what tools are available and what they can be used for is a task best done early in the Android learning process, so that, when you are faced with a problem, you have some clue as to which utility might be able to help you find a solution. Most of the Android development tools are integrated into Eclipse using the ADT plug-in, but they can also be launched independently—you’ll find the executables in the /tools subdirectory of the Android SDK installation. In this chapter, we walk through a number of the most important tools available for use with Android. This information will help you develop Android applications faster and with fewer roadblocks.

Using the Android Documentation

Although it is not a tool, per se, the Android documentation is a key resource for Android developers. An HTML version of the Android documentation is provided in the /docs subfolder of the Android SDK documentation, and this should always be your first stop when you encounter a problem. You can also access the latest help documentation online at the Android Developer website, http://developer.android.com (http://goo.gl/K8GgD, see Figure 2.1 for a screenshot of the Dev Guide tab of this website).

Image

Figure 2.1. The Android Developer Website

The Android documentation is divided into seven sections:

Home—This tab provides some high-level news items for Android developers, including announcements of new platform versions. You’ll also find quick links for downloading the latest Android SDK, publishing your applications on the Android Market, and other helpful information.

SDK—This tab provides important information about the SDK version installed on your machine. One of the most important features of this tab is the release notes, which describe any known issues for the specific installation. This information is also useful if the online help has been upgraded, but you want to develop to an older version of the SDK.

Dev Guide—This tab links to the Android Developer’s Guide, which includes a number of FAQs for developers, best practice guides, and a useful glossary of Android terminology for those new to the platform. The Appendix section also lists all Android platform versions (API Levels), supported media formats, and lists of intents.

Reference—This tab includes a searchable package and class index of all Android APIs provided as part of the Android SDK, in a Javadoc-style format.

Resources—This tab includes links to articles, tutorials and sample code, as well as acting as a gateway to the Android developer forums. There are many Google groups that you can join, depending on your interests.

Videos—This tab, which is available online only, is your resource for Android training videos. Here, you find videos about the Android platform, developer tips, and the Google I/O conference sessions.

Blog—This tab links to the official Android developer blog. Check here for the latest news and announcements about the Android platform. This is a great place to find how-to examples, learn how to optimize Android applications, and hear about new SDK releases and Android Developer Challenges.

Now is a good time to get to know your way around the Android SDK documentation. First, check out the online documentation and then try the local documentation (available in the /docs subdirectory of your Android SDK installation).

Debugging Applications with DDMS

The Dalvik Debug Monitor Service (DDMS) is a debugging utility that is integrated into Eclipse through a special Eclipse perspective. The DDMS perspective provides a number of useful features for interacting with emulators or devices and the applications being debugged (see Figure 2.2).

Image

Figure 2.2. The DDMS Perspective in Eclipse

The features of DDMS are roughly divided into six functional areas:

• Task management

• File management

• Memory management

• Emulator interaction

• Logging

• Screen captures

DDMS and the DDMS perspective are essential debugging tools. Now, let’s look at how to use these features in more detail.

Debugging from the DDMS Perspective

Within the DDMS perspective, you can choose a specific process on an emulator or a device and then click the Debug button(Image)to attach a debugger to that process. You need to have the source code in your Eclipse workspace for this to work properly. This works only in Eclipse, not in the standalone version of DDMS.

Managing Tasks

The top-left corner of the DDMS perspective lists the emulators and devices currently connected. You can select individual instances and view its processes and threads. You can inspect threads by clicking the device process you are interested in—for example, com.androidbook.hellokindle—and clicking the Update Threads button (Image), as shown in Figure 2.3. You can also prompt garbage collection on a process and then view the heap updates by clicking the Update Heap button (Image). Finally, you can stop a process by clicking the Stop Process button (Image).

Image

Figure 2.3. The Threads Tab in DDMS

Browsing the Android File System

You can use the DDMS File Explorer to browse files and directories on the emulator or a device (see Figure 2.4). You can copy files between the Android file system and your development machine by using the Push (Image) and Pull (Image) buttons available in the top right-hand corner of the File Explorer tab.

Image

Figure 2.4. The File Explorer Tab in DDMS

You can also delete files and directories by using the Delete button (Image) or just pressing Delete. There is no confirmation for this delete operation; nor can it be undone.

Taking Screenshots of the Emulator or Device

One feature that can be particularly useful for debugging both devices and emulators is the ability to take screenshots of the current screen (see Figure 2.5).

Image

Figure 2.5. Taking a Screenshot Using DDMS

The screenshot feature of the DDMS perspective is particularly useful when used with real devices. To take a screen capture of what’s going on at this very moment on your device, follow these steps:

1. In the DDMS perspective, choose the device (or emulator) you want a screenshot of. The device must be connected via USB.

2. On that device or emulator, make sure you have the screen you want. Navigate to it, if necessary.

3. Press the Screen Capture button (Image) to take a screen capture. This launches a capture screen dialog.

4. The Rotate button rotates the Device Screen Capture tool to display in portrait mode. This is useful for Kindle Fire screen captures.

5. Within the capture screen dialog, click the Save button to save the screenshot to your local hard drive. This tool does not show a live view, just a snapshot; click the Refresh button to update the capture view if you make changes on the device. The Copy button places the image on your system’s clipboard for pasting into another application, such as an image editor. Click the Done button to exit the tool and return to the DDMS perspective.

Viewing Log Information

The LogCat logging utility that is integrated into the DDMS perspective allows you to view the Android logging console. You may have noted the LogCat logging tab, with its diagnostic output, in Figure 2.2 earlier in this chapter. We talk more about how to implement your own custom application logging in Chapter 3, “Building Kindle Fire Applications.”

Eclipse has the ability to filter logs by log severity. You can also create custom log filters by using tags.

Working with the Android Emulator

The Android emulator is probably the most powerful tool at a developer’s disposal. It is important for developers to learn to use the emulator and understand its limitations. The Android emulator is integrated with Eclipse, using the ADT plug-in for the Eclipse IDE.

The Android emulator is a convenient tool, but it has some limitations:

• The emulator is not a device. It simulates generic device behavior, not specific hardware implementations or limitations. This is particular noticeable with Kindle Fire emulation; not even the home screen is the same. None of the custom Amazon Kindle Fire experience is emulated at this time.

• Sensor data, battery and power settings, and network connectivity are all simulated using your computer.

• No Kindle Fire built-in apps are present on the emulator.

Using the Android emulator is not a substitute for testing on a true Android device.

Providing Input to the Emulator

As a developer, you can provide input to the emulator in a number of ways:

• Use your computer mouse to click, scroll, and drag items (for example, sliding volume controls) onscreen, as well as on the emulator skin.

• Use your computer keyboard to input text into controls.

• Use your mouse to simulate individual finger presses on the soft keyboard or physical emulator keyboard.

• Use a number of emulator keyboard commands to control specific emulator states.

Using Other Android Tools

Although we’ve already covered the most important tools, a number of other special-purpose utilities are included with the Android SDK. A list of the tools that come as part of the Android SDK is available on the Android developer website (http://goo.gl/yzFHz). Here, you can find a description of each tool and a link to its official documentation.

Summary

The Android SDK ships with a number of powerful tools to help with common Android development tasks. The Android documentation is an essential reference for developers. The DDMS debugging tool, which is integrated into the Eclipse development environment as a perspective, is useful for monitoring emulators and devices. The Android emulator can be used for running and debugging Android applications virtually, without the need for an actual device. There are also numerous other tools for interacting with physical devices and emulators in a variety of situations.

Exercises

1. Head over to the Android Developer’s Guide website at http://d.android.com/guide. Consider reading the article “Android Basics: What is Android?” (http://d.android.com/guide/basics/what-is-android.html).

2. Launch the Android emulator. Get familiar with how the emulator tries to mimic a real Kindle Fire device. Note the limitations.

3. Launch the HelloKindle application you wrote in Chapter 1, “Getting Started with Kindle Fire,” and explore it using the DDMS tool.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset