letters or in all capitals.
content particular to your business, training goals, marketing focus, and branding interests.
Android SDK / James Steele, Nelson To.
(Computers) I. To, Nelson, 1976- II. Title.
Text printed in the United States on recycled paper at RR Donnelley, Crawfordsville, Indiana.
and wireless carriers to appeal to just about anyone.
faction of creating a relevant app.
many in the Android developer community, is clear and well-explained documentation.
In addition, a clear working example is worth a thousand words of documentation.
coding style and help to shape other parts of the developer’s code.
and start using whatever is necessary.
techniques are included in each recipe as needed to support the main recipe.
Be able to write an Android Application from scratch.
Be able to write code that works across multiple versions of Android.
Have a large reference of code snippets to quickly assimilate into applications.
Understand the unique aspects of Android programming techniques.
project is organized. It also focuses on the activity as a main application building block.
as touch events and gestures.
presents and participates in various Silicon Valley new technology groups.
both in the Bay Area and China.
Android to the forefront in just a few years.
books, televisions, set-top boxes, and even automobiles, have also adopted the Android OS.
in the rest of this book.
Research In Motion has developed and held so well with its Blackberry models.
ing applications across all environments is an impossible task.
main threads discussed throughout this book.
Still, as with any embedded platform, extensive testing of applications is required.
from users to developers of Android Market applications.
only in understanding what Android is, but what it is not.
inaccessible to developers (such as Global Positioning System (GPS) navigation).
OS is built for embedded platforms, and Chrome OS is built for cloud-based platforms.
a convergence that might have been in the cards all along.
resides on the baseband processor, which connects to the radio hardware.
(BT), and Wi-Fi (802.11), although there are variations.
themselves could be stored only on the internal ROM.
running Android, including Google’s Nexus One.
video at 720p. Most smartphones that have followed also utilize a 1-GHz microprocessor.
colors based on the notification.
the first commercially available phone that supports WiMAX (802.16e-2005).
that a significant fraction of Android phones accessing the Android Market are Droids.
kets for receiving Mobile ATSC signals.
first phones to offer Bluetooth 3.0 compatibility.
tend to be more like smartphones with large screens.
tures.Android is mainly used for GPS navigation but can also support web browsing.
Android Market from the television.
most of the differences are transparent to the developer and not covered further here.
device-independent code. Screens, user input methods, and sensors are discussed here.
deeper blacks and lower power.
1.3. Note that Table 1.1 provides the screen density classification for each device listed.
can be less than resistive.
few early exceptions, all support multitouch.
Smartphones are becoming sensor hubs in a way, opening a rich experience for users.
seen with the additional sensors.
accelerometer and magnetometer to determine the orientation.
package with an 8-bit Hall-effect magnetometer and temperature sensor.
the screen backlight and LED flash appropriately.
ambient light sensor combined into one.
hardware.These differences can lead to varying performance and accuracy of the sensors.
and utilize them as much as possible.
prices and trigger an alert as necessary.
outside temperature, while other applications are running.
than one finger down at the same time.This is often used to zoom or rotate a view.
be considered and tested for any user interface (UI) layout.
This book is focused on writing Android code, the main aspect of Android development.
than presented in the recipes.
whole additional file just to define them.
ure. It also helps with more advanced tasks, such as signing an application for distribution.
on an actual device running Android 2.1, and as needed,Android 1.5 or Android 2.2.
done with an action Android device.
Do not use internal or unsupported APIs.
to turn on GPS or data roaming by itself, but this is no longer allowed.
10 deep or 30 total) can cause crashes.
behavior. Screen orientation can be locked, as described in Chapter 2.
various places throughout the book.
either can be used, the Android library is best.
Test thoroughly, including different environments and devices if possible.
Kit and has an integrated plugin for the Eclipse Integrated Development Environment.
steps should be done on a host computer used as the development environment.
needs to be unzipped in place and is ready to use.
Windows, this just needs to be unzipped in place and is ready to use.
Google Inc.; and Android API 8).
to be used with each Android application (or similar for a Debug Configuration).
Android JUnit tests can be configured here, too.
new hardware roll-outs (such as Eclair’s release with Droid).
single number: the API level.
Smart virtual (soft) keyboard, support for third-party keyboards.
Raw audio recording and playback.
Removed end-user root access (unless tethered to computer and using SDK).
Speech recognition via RecognizerIntent (cloud service).
Faster GPS location gathering (using AGPS).
Support for multiple screen sizes.
Integrate with the Quick Search Box using the SearchManager.
Virtual Private Network (VPN) support.
Sync adapter APIs to connect to any backend.
Embed Quick Contact accessible in applications.
Applications can control the Bluetooth connection to devices.
Multitouch is accessible through the MotionEvent class.
Just-In-Time compilation (JIT) enabled, leading to faster code execution.
Car and desk dock themes.
Better definition of multitouch events.
Applications can request to be installed on the SD memory card.
Wi-Fi tether support on select devices.
Thumbnail utility for videos and images.
Multiple language support on keyboard input.
Application error reporting for Market apps.
of additional features for developers remains high and worthwhile to utilize.
list of keyboard shortcuts for emulator functions is shown in Table 1.4.
Some settings on the Android device need to be changed to enable developer usage.
are provided in Chapter 12.
commands are introduced in Chapter 12.
upgraded, the same key needs to sign it to ensure a transparent update for the user.
erations for publication of an app are provided here for reference.
symbol to an Android app is discussed in Chapter 4.
increase visibility for an application.
tion is pushed off the “Just in” list within a day or two.
words users might use and include those in either the title or description of the app.
porting website is often superfluous, as people browsing the mobile market rarely use it.
said, one must be careful to avoid using copyrighted material.
application have permission to access the Internet and the location of the device.
potential customers from installing the app.
to third-party app stores for distribution.
levels), but not all apps can be partitioned this way.
it is catching on in the mobile world.
version and adapting to the user feedback. Users like to see a developer who is responsive.
increases, it adds validity to the app.
good reason to upgrade, they might not.
focus of this chapter turns to activities and the intents that launch them.
which is specified by a Java base class.
them, too, within the specified permissions.
for a graceful operation, such as saving variables or restoring user interface (UI) elements.
2.Fill in the Project name, such as SimpleActivityExample.
4.Fill in the Application name, such as Example of Basic Activity.
5.Fill in the Package name, such as com.cookbook.simple_activity.
fill in an Activity name, such as SimpleActivity.
should be called first to properly initialize the activity, as shown in Listing 2.1.
it is called main.xml, as shown in Listing 2.2.
ered in more detail in Listing 2.5.
as seen in the Eclipse IDE.
needs to be changed or reused.
Figure 2.1 shows an example project structure, as seen from the Eclipse Package Explorer.
src/ contains the Java packages the developer writes or imports for the application.
Each package can have multiple .java files representing different classes.
res/layout/ contains the XML files that specify the layout of each screen.
res/values/ contains the XML files used as references by other files.
assets/ contains additional nonmedia files the application uses.
AndroidManifest.xml specifies the project to the Android OS.
gen/ contains autogenerated code, including the generated class R.java.
Referencing resources from within Java or XML files is demonstrated in Table 2.2.
Chapter 4,“User Interface Layout,” but this suffices to cover the recipes in this chapter.
ating a Project and an Activity” recipe.
have major and minor revisions declared.
seen as it is utilized in different recipes.
level possible when specifying this.
fices to cover the recipes in this chapter.
2.Right-click the project and Refactor → Rename the project.
1. Right-click the package and Refactor → Rename the package.
2. Edit the AndroidManifest.xml to ensure the new package name is reflected.
1. Right-click the .java file and Refactor → Rename the class.
corresponding references in the Java code.
example of each of these functions.
Changing the screen orientation destroys and recreates the activity from scratch.
Pressing the Home button pauses the activity, but does not destroy it.
old one was not destroyed.
Letting the screen sleep pauses the activity and the screen awakening resumes it.
mentioning two additional simple recipes that can control this behavior.