Book Review: Building Applications with the Android SDK, 2nd Edition
In the newest edition of The Android Developer’s Cookbook: Building Applications with the Android SDK, 2nd Edition, a collaborative effort by Ronan Schwarz, Phil Dutson, James Steele and Nelson To, the authors have succeeded in their efforts to provide another solid reference book to the Addison-Wesley Developer’s Library Series. This book for mobile app developers can serve as an authoritative guide for newbies. It also will help support intermediate to expert devs in continuing and enhancing their sound programming practices.
Readers will learn how to write their own code while incorporating the book’s prefab recipes, code snippets and User Interface (UI) Layouts to quickly add tasks into an Android Project to create their own original app.
Highlighted in the book is how to get along with Android’s basic Application Programming Interfaces (API’s) to make sure that your app will coexist with its fragmented device pool and different OS versions; past, present and future. The authors explain the ongoing relationship between Android; the Linux kernel, the Java framework and the Eclipse Integrated Development Environment (IDE).
They note how the modifications made to the OS that enable it to function in the arena of the mobile ecosystem, with its smaller screens and limited options, dictate the need for selecting the proprietary Android libraries wherever possible. As opposed to Java libraries like Swing or Timer and typical Linux utilities X Windows or GNU C libraries, which are unsuitable for coding in Android.
Right from chapter one the reader delves into the very nuts and bolts of the World’s most popular mobile OS. How the essential files that comprise it, kept safely in nonvolatile flash memory, are comprised of six images:
- Bootloader- Begins the loading of the boot image at startup
- Boot image- Kernal and RAMDisk
- System image- OS platform with apps
- Data image- Saves user’s data over the different power modes
- Recovery image- Preserves updates and rebuilds files
- Radio image- keeps the radio stack files
The writers instruct developers on the intimate association of the hardware to the code that they write. They stress the importance of considering the growing diversity not only in memory and processing power, wealth of screen sizes, resolutions, front and rear cameras, between smartphones and tablets of existing Android hardware. But also of the burgeoning categories of entirely new device types that are now or will soon be running the OS. Such as; smart watches, exercise equipment, medical devices, automobiles and even gaming consoles, to encourage them to as much as possible, write device-neutral code.
The authors stress the importance of seeing the big picture when designing your app. Meaning that developers should have a clear vision of what the finished app will look like. The four-man writing team packs reams of expert advice and experience into their cookbook.
They recommend using the Eclipse IDE to ensure optimum setup when creating your Android project.
Here’s a sample recipe:
Activities and Intents
The steps to do this are similar to the ones described in the previous recipe:
1. In Eclipse, choose File → New → Android Application Project.
2. Fill in the project name, such as SimpleFragmentExample.
3. Fill in the application name, such as Example of Basic Fragments.
4. Fill in the package name, such as com.cookbook.simplefragments.
5. Select a minimum required SDK of API Level 11 or Android Honeycomb.
Fragments can be used in lower API versions only if the support library extra is installed on the machine.
6. In the Create Activity screen, choose MasterDetailFlow as the start point.
7. Name the items used for demo purposes; for instance, fruits.
8. Press Finish to create the sample project.
Exploring the possibilities of this sample is left to the reader. Here, instead, a few important things about fragments are highlighted. Fragments come with their own lifecycle, which is dependent on the hosting activities. As fragments can be added, shown, hidden, and removed at any time during the lifecycle of an activity, their existence is much more short-lived than that of other components. Similar to an activity, a fragment has onPause(), onResume(), onDestroy(), and onCreate() methods.
It is to be noted, however, that onCreate(Bundle) is the second method called on a fragment; the first one is onAttach(Activity), which signals that there is a connection to the hosting activity now. Methods can be called on the activity here; however, it is not guaranteed that the activity has been fully initialized itself. Only after onActivityCreated() is called is the activity passed through its own onCreate() method.
Given that fragments can be instantiated and added at much later times, the state of the activity in onAttach() should not be relied upon. The method used to initialize views and start most work is onCreateView(LayoutInflater, ViewGroup, Bundle). The Bundle class given here is the saved instance state, if the fragment is re-created. Fragments use bundles also for serializing arguments. Every parcelable type of external information a fragment needs can be obtained from the hosting activity by calling setArguments() and can always be read in the fragments with the getArguments() call. This allows information coming from the starting intent of the activity to be passed directly to the fragment to be shown.
One of the most important features of any app is the User Interface (UI). In the Android Developer’s Cookbook’s chapter five we learn the three key elements to a basic UI layout; screen views, screen touch events and key presses that will define the attributes of your app. It includes a summary of the complete set of resource directories such as res/animator/- for animation and res/menu- for XML files, which selects menus.
For every UI object there are three definable attributes to tweak your UI’s look and performance; object dimension, object text and object color. To add consistency to the performance of their app, readers are instructed on how to use a global resource file, which also assists them in keeping track of each of the three attributes.
Chapter thirteen is for those material developers that want to monetize their apps with Google Play’s In-App Billing. To get In-App Billing up and running you’ll need to have a Google Play merchant account to link with your developer account. Everything that you require to do that will be found in the Extras area of the SDK Manager in the Android SDK.
With four authors, one might think that there could be too many chefs spoiling the cookbook. Not so. When it comes to solid advice on how to code apps for the open source Android mobile operating system, unlike the fragmentation of device types and OS versions that are the norm, there isn’t a clue or passage that might serve as a distinction between the writers’ personal styles. That there isn’t indicates just how in sync and on the same page the writers are.
The Android Developer’s Cookbook: Building Applications with the Android SDK, 2nd Edition is a nice addition to any developer’s book shelf. Use it to keep your mobile developing chops from getting stale. You can always refer to it when you need to be reminded of something.
About the Book Authors
Ronan 'Zero' Schwarz is Co-Founder of OpenIntents, an open-source company specializing in Android development. Ronan has over 15 years of programing experience, in a wide variety of fields like augmented reality, web, robotics and business systems, as well as different programing languages including C, Java and Assembler. Ronan has been working on the Android Platform since 2007, and has helped creating SplashPlay and Droidspray, both top finalists of the Google Android Developer Challenge I and II. He is currently working with SinnerSchrader Mobile as a Consultant in Berlin, Germany. Ronan regularly speak at conferences in Europe, and is an Android dev luminary.
Phil Dutson is the lead front-end and mobile developer for ICON Health and Fitness. He has worked on projects and solutions for NordicTrack, ProForm, Freemotion, Sears, Costco, Sam’s Club and others. Through the years he has been using, tweaking, and writing programs for mobile devices from his first Palm Pilot 5000 to his current collection of iOS and Android devices. Phil is the author of 3 books jQuery, JQuery UI, and jQuery Mobile; Sams Teach Yourself jQuery Mobile in 24 hours, and Creating QR and Tag Codes.
James Steele actively presents and participates in various Silicon Valley Android and new technology groups. His work at Sensor Platforms focuses on making user motion and context information available, while shielding applications developers from the complexity and physics of sensor hardware. Before joining Sensor Platforms, Dr. Steele held senior management positions at Spansion, Polaris Wireless and ArrayComm, as well as research positions in theoretical and particle physics at Massachusetts Institute of Technology and Ohio State University. He holds a Ph. D. in theoretical physics from State University of New York at Stony Brook.
Nelson To has been working on Android Research and Development for years. He has a great passion on exploring innovative ideas and creating the Android applications to make his ideas a reality. He has developed a plethora of Android applications including AOL AIM Android application, and the first High Definition video chatting android application (Vid)in the history on the Google TV for Logitech Revue Box. He also teaches Android classes in the local community to help people to learn the Android more effectively, and devotes significant amount of effort in the Android community to organize the Android meetings for the local community.
Mike Amundsen May 29, 2015
Ben Linders May 28, 2015