Chapter    1

Welcome to Android

I would like to welcome you to this book, Beginning Android, 5th Edition. This is a new edition of the book, but I’m sure this is not the first time you have encountered Android—either by using one of the billion or more Android devices currently activated throughout the world, or by hearing about it from friends, colleagues, or the media. It is hard to escape Android; not only is it the world’s most prevalent mobile device operating system, but it keeps growing. Google reports that it sees more than one million Android devices activated every day.

If the growth doesn’t excite you, then the diversity of Android devices should. We all know Android was developed for phones, and later, for tablets. But did you know that it now powers everything from inflight entertainment systems, to TVs, headsets, glasses, watches, shoes, games consoles, and even a brand of Japanese toilet? As Android grows, so does people’s need for great applications they use on their devices. And that is where this book helps. As a new Android developer, it will be natural for you to use this book in conjunction with online searches, and I encourage you to do that. Be aware, however, that because Android has rapidly changed over the last eight years, the material you find online can be of varying quality and applicability. Sites like Stack Overflow are excellent resources, but it’s prudent to check for what version of Android (or in what year) their content was written.

The Fast Path to Learning Android Development

Given the plethora of devices, you might be left wondering where to start. Too many choices can lead to indecision, and I want to get you, the reader, working with Android as quickly as possible. To help you make a rapid start, this book largely focuses on the original and most common device type on which Android runs: the smartphone. I extend that to also include tablets, since they have matured to be mainstream devices and the line is blurred between phones and tablets in any case—thus the current “Phablet” trend.

This focus on phones helps you in lots of ways right from the start. You will be learning skills and approaches for the largest device market in history, so your applications will have the biggest possible audience. And you will also be learning the largest, richest, and most mature parts of Android development. Don’t worry, though! I also cover the leading edge of Android later in the book, so you can also start mastering topics like Google Glass and Android Wear.

Thinking in a Smartphone Mindset

As a reader of this book, you might well be new to Android development, but your background as a developer in other areas, your technology expertise, and your know-how is harder to predict. Before we delve into your first look at Android code and the building blocks of an Android device, it is useful to start with some understanding of the fundamentals common to all Android development on smartphones and tablets.

Computing on the Go!

The first, and most obvious, point to make about thinking like an Android developer is that Android devices may have their roots in mobile phones, but today, actually making and receiving phone calls is only a minor part of their popularity and pervasiveness. You should think of the billion or more Android devices in circulation as little engines of mobile computing that just happen to be able to make phone calls as one of their many capabilities. They are literally mobile computers!

Size Matters

In developing for Android, you are dealing with screens of many sizes, but one thing in common for the vast, vast majority of mobile Android devices is that you are working with small screens or displays. Although you may develop for Android with the comfort of a full-sized desktop on a modern notebook computer, your target audience, at the extreme, will have only a square inch or so of display real estate on which to enjoy your development efforts.

The Interface Is More Than the Screen

Modern smartphones are more than just a screen for viewing text and other content. Phones make calls, play music, vibrate and provide haptic feedback for games, sense the temperature, report direction and location, and much more. When you think of the way in which your users might interact with your applications, think beyond the simple visual screen. A phone interacts with multiple senses, and you should design with all of them in mind.

You Are Not Alone

Yours will not be the only application running on someone’s Android device. In fact, they may not just have other applications, but other applications that can do similar—or even the same—work as your own. Be mindful that you cannot hog all of the device and all of its features. Also keep in mind that for your users, it is two simple taps of a finger for them to switch to another application.

In later chapters, I also cover how resources and capabilities are shared and managed across an Android device, and how being aware that your application can be interrupted at any time is one of the key use cases you need to consider when developing Android applications.

Translating Developer Dreams into Android Action

Now that you know how to think about developing for Android, you might also be thinking that it sounds like a lot of compromises, and is that all there is to it? The good news is that by taking care of a bunch of heavy lifting for you and by providing you with an amazing array of support, tools, and the foundation on which to build applications of all sorts, Android lets you focus on the essentials of mobile development.

First, Android’s dominant programming language is Java. That’s good, because it is one of the most widely used languages on the planet. When you are developing, you get to use the vast majority of standard Java, as well as additional libraries the community has added over the years since Android’s public release.

Second, you have access to a range of development tools that are totally free! Yes, free. Google provides not one, but two, free integrated development environments (IDEs) from which to choose in which you can let your developer imagination go wild. We discuss both of these in more detail in Chapter 2, but for now, you can rest easy knowing you can work with either or both—Android Developer Tools (ADT) in Eclipse, or Android Studio, which is an IntelliJ IDEA–based IDE.

Third, many additional tools—such as emulators, performance monitors, templates, design tools, runtime environments, and more—have been added to the developer’s world. And that’s not all: you can write an entire book on this! Joking aside, Android does ask you to adopt a different development mindset to the one you need to design traditional desktop applications, but then it makes an enormous effort to support you every step of the way.

A Look Inside Android

To finish your introduction to thinking like an Android developer, let me introduce the fundamental building blocks of Android applications. I cover each of these areas in much more detail in the coming chapters.

Activities are the fundamental “screens” or UI elements with which users interact. Because of the nature of Android and the many display sizes with which you might work, a user might see one or more activities as part of the user interface at any one time. Activities are easy for you to design and develop, and they are easy for users to launch and use. Your target Android systems love activities, so feel free to be prolific in your creation and use of them!

Intents are messages passed between applications and the Android environment and are akin to events-driven messaging in modern desktop development environments. You can write your applications so they listen out for events and respond appropriately—whether that’s answering a phone call, reacting to information from onboard sensors, or responding to changes in application state. Even better, you can create and pass your own intents, expanding the capabilities of your applications and others on the same device.

Services are background applications that provide features, abilities, or actions on which your applications (and their activities) can rely. Much like services or daemons in other operating systems, Android services are long-lived and generally run without a visible user interface (UI). Some services do provide visual elements, and you’ll learn more about services in Chapter 22.

Content providers are a convenient abstraction to the many types and sources of data you might want to use in your application. In traditional development environments, you have to worry about all the tedious logistics of working with files, databases, network sockets, protocols, and the like. Android vastly simplifies your life as a developer by supporting the content provider metaphor for any data that needs to be shared on the device (and even for off-device data). When building your own applications, you are also able to define and develop your own content providers to enable data sharing with other applications, without needing to work with low-level storage issues, proprietary query languages, odd protocol considerations, or any other baggage.

A Look Inside This Book

With your mind now surging with thoughts of Android development, here’s the roadmap of how we’ll explore all of the topics already mentioned, and more.

  • The next three chapters complete Part I of the book; you’ll code your first Android application in the very next chapter! No delays, no excuses. After you write your first Android application, we’ll then pull it apart to ensure you are familiar with the real-world code that represents the concepts I’ve already described here. We’ll also tinker with and explore what Android is doing for you, and what you need to be doing yourself as a nascent Android developer.
  • Part II helps you master the world of activities and the possibilities for user interface magic with Android. I cover all the essential components at your disposal for interface design and behavior and how mobile-specific concepts like device rotation work.
  • Part III expands on your new knowledge of interface design for Android and introduces you to the power and flexibility of fragments. Fragments allow you to work with devices of any size, from 1 inch to 100 inches! As well as displays, we also explore input devices such as the camera, the microphone, and other onboard capabilities.
  • Part IV delves behind the scenes, building your knowledge of services, resource handling, and other powerful components of Android that you will want to use to make the best possible applications.
  • Part V, the final part of the book, takes you the frontiers of Android and looks at a range of topics, such as Google Play services, cloud-based facilities you can incorporate into your application, and the explosive growth in wearable Android with Google Glass and Android Wear.

Now that you have had a proper introduction to Android development and know where you are going, it’s time to get started actually developing your first Android application!

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

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