09-04-2012, 01:56 PM
The Android Developer Cookbook
The Android Developer_s Cookbook (7Summits).pdf (Size: 3.42 MB / Downloads: 309)
Overview of Android
The Android operating system (OS) has come a long way since the announcement of
the Open Handset Alliance in late 2007.The idea of an open source OS for embedded
systems was not new, but Google aggressively backing it definitely has helped push
Android to the forefront in just a few years.
Many wireless carriers in multiple countries across various communication protocols
have one or more Android phones available. Other embedded devices, such as tablets, netbooks,
televisions, set-top boxes, and even automobiles, have also adopted the Android OS.
This chapter discusses various general aspects of Android useful for a developer. It provides
a foundation for the creation of Android applications and a context for the recipes
in the rest of this book.
Hardware Differences on Android Devices
The hardware available on each Android device varies, as seen in Table 1.1. In general,
most of the differences are transparent to the developer and not covered further here.
However, a few hardware differences are important to understand to assist in writing
device-independent code. Screens, user input methods, and sensors are discussed here.
User Input Methods
Touchscreens enable users to interact with the visual display.There are three types of
touchscreen technology:
n Resistive—Two resistive material layers sit on top of a glass screen.When a finger,
stylus, or any object applies pressure, the two layers touch together and the location
of the touch can be determined. Resistive touchscreens are cost-effective, but
only 75 percent of the light shows through, and until recently, multitouch was not
possible.
n Capacitive—A charged material layer is overlaid on a glass screen.When a finger or
any conductive object touches the layer, some charge is drawn off, changing the
capacitance, which is measured to determine the location of the touch. Capacitive
touchscreens allow as much as 90 percent of the light through, although accuracy
can be less than resistive.
n Surface Acoustic Wave—This uses a more advanced method that sends and receives
ultrasonic waves.When a finger or any object touches the screen, the waves are absorbed.
The waves are measured to determine the location of the touch. It is the
most durable solution, but more suitable for large-scale screens such as automatic
bank tellers.
Sensors
Smartphones are becoming sensor hubs in a way, opening a rich experience for users.
Other than the microphone that every phone has, the first additional sensor introduced
on phones was the camera. Different phone cameras have varying capabilities, and this is
an important factor for people in selecting a device.The same type of diversity is now
seen with the additional sensors.
Recipe: Debugging Through Breakpoints
Developers can also run applications in debug mode and insert breakpoints to freeze an
application in run-time. First, the application needs to be launched in debug mode, which
displays the dialog shown in Figure 12.4. If Yes is selected, it switches to the Debug perspective