Mobile Application BSCS, Schemes and Mind Maps of Mobile Computing

With our tool, you can quickly generate descriptions for your books, saving you time and energy. Works with any kind of book. No matter the genre, our Book Description Generator will work to provide you with a great book description. I also work for Kindle, Amazon, or Goodreads books and novels. Try it today!

Typology: Schemes and Mind Maps

2018/2019

Uploaded on 12/20/2022

Noorii610
Noorii610 🇵🇰

4 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
c01.in
dd
09/08/2016 Pa
g
e
1
WHAT Y
OU
WILL LEARN IN THI
S
CH
APTER
W
hat
i
s
An
d
r
o
i
d?
An
d
r
o
i
d
v
e
r
s
i
o
n
s
a
n
d
i
ts
f
eatu
r
e
s
Th
e
An
dr
o
i
d
a
r
ch
i
tectu
r
e
T
he
v
a
ri
ous
An
d
r
o
i
d
de
vi
ces
o
n
the
m
a
r
ket
The Android Market a
pp
lication store
How to obtain the tools and SDK for developing Android
a
pp
lications
How to develop your fi rst Android application
CO
DE D
O
WNL
O
A
D
There are no code downloads for this cha
p
ter.
W
elcome to the world of Android! This cha
p
ter ex
p
lains what Android is and what makes it so
com
p
ellin
g
to both develo
p
ers and device manufac turers. It also shows
y
ou how to obtain and
s
et u
p
all the necessar
y
tools so that
y
ou can test
y
our a
pp
lication on an Android emulator in
Android Studio 2 and how to
g
et started with develo
p
in
g
y
our fi rst Android a
pp
lication. B
y
the
e
nd of this cha
p
ter,
y
ou will be e
q
ui
pp
ed with the basic knowled
g
e
y
ou need to ex
p
lore more
s
o
p
histicated techni
q
ues and tricks for develo
p
in
g
y
our next killer Android a
pp
lication.
1
COPYRIGHTED MATERIAL
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download Mobile Application BSCS and more Schemes and Mind Maps Mobile Computing in PDF only on Docsity!

WHAT YOU WILL LEARN IN THIS CHAPTER

➤ (^) What is Android? ➤ (^) Android versions and its feature set ➤ (^) The Android architecture ➤ (^) The various Android devices on the market ➤ (^) The Android Market application store ➤ (^) How to obtain the tools and SDK for developing Android applications ➤ (^) How to develop your first Android application

CODE DOWNLOAD There are no code downloads for this chapter.

Welcome to the world of Android! This chapter explains what Android is and what makes it so compelling to both developers and device manufacturers. It also shows you how to obtain and set up all the necessary tools so that you can test your application on an Android emulator in Android Studio 2 and how to get started with developing your fi rst Android application. By the end of this chapter, you will be equipped with the basic knowledge you need to explore more sophisticated techniques and tricks for developing your next killer Android application.

COPYRIGHTED MATERIAL

2 ❘ CHAPTER 1 GETTING STARTED WITH ANDROID PROGRAMMING

WHAT IS ANDROID?

Android is a mobile operating system that is based on a modified version of Linux. It was originally developed by a startup of the same name, Android, Inc. In 2005, as part of its strategy to enter the mobile space, Google purchased Android, Inc. and took over its development work (as well as its development team). Google wanted the Android OS to be open and free, so most of the Android code was released under the open source Apache License. That means anyone who wants to use Android can do so by downloading the full Android source code. Moreover, vendors (typically hardware manufacturers) can add their own proprietary extensions to Android and customize Android to differentiate their products from others. This development model makes Android very attractive to vendors, especially those companies affected by the phenomenon of Apple’s iPhone, which was a hugely successful product that revolutionized the smartphone industry. When the iPhone was launched, many smart- phone manufacturers had to scramble to find new ways of revitalizing their products. These manu- facturers saw Android as a solution, meaning they will continue to design their own hardware and use Android as the operating system that powers it. Some companies that have taken advantage of Android’s open source policy include Motorola and Sony Ericsson, which have been developing their own mobile operating systems for many years. The main advantage to adopting Android is that it offers a unified approach to application develop- ment. Developers need only develop for Android in general, and their applications should be able to run on numerous different devices, as long as the devices are powered using Android. In the world of smartphones, applications are the most important part of the success chain.

Android Versions Android has gone through quite a number of updates since its fi rst release. Table 1-1 shows the various versions of Android and their codenames.

TABLE 1-1: A Brief History of Android Versions

ANDROID VERSION RELEASE DATE CODENAME

1.1 February 9, 2009

1.5 April 30, 2009 Cupcake

1.6 September 15, 2009 Donut

2.0/2.1 October 26, 2009 Éclair 2.2 May 20, 2010 Froyo

2.3 December 6, 2010 Gingerbread

3.0/3.1/3.2 February 22, 2011 Honeycomb

4.0 October 18, 2011 Ice Cream Sandwich

4 ❘ CHAPTER 1 GETTING STARTED WITH ANDROID PROGRAMMING

Architecture of Android To understand how Android works, take a look at Figure 1-1, which shows the various layers that make up the Android operating system (OS). The Android OS is roughly divided into five sections in four main layers:

➤ (^) Linux kernel —This is the kernel on which Android is based. This layer contains all the low-level device drivers for the various hardware components of an Android device. ➤ (^) Libraries —These contain the code that provides the main features of an Android OS. For example, the SQLite library provides database support so that an application can use it for data storage. The WebKit library provides functionalities for web browsing. ➤ (^) Android runtime —The Android runtime is located in the same layer with the libraries and provides a set of core libraries that enable developers to write Android apps using the Java programming language. The Android runtime also includes the Dalvik virtual machine, which enables every Android application to run in its own process, with its own instance of the Dalvik virtual machine. (Android applications are compiled into Dalvik executables). Dalvik is a specialized virtual machine designed specifically for Android and optimized for battery-powered mobile devices with limited memory and CPU power. ➤ (^) Application framework —The application framework exposes the various capabilities of the Android OS to application developers so that they can make use of them in their applications. ➤ (^) Applications —At this top layer are the applications that ship with the Android device (such as Phone, Contacts, Browser, and so on), as well as applications that you download and install from the Android Market. Any applications that you write are located at this layer.

Android Devices in the Market Android devices come in all shapes and sizes including, but not limited to, the following types of devices: ➤ (^) Smartphones ➤ (^) Tablets ➤ (^) E-reader devices ➤ (^) Internet TVs ➤ (^) Automobiles ➤ (^) Smartwatches

Chances are good that you own at least one of the preceding devices. Figure 1-2 shows the Samsung Galaxy Edge 7.

Home

Contacts

Browser

...

A PPLICATIONS

APPLICATION FRAMEWORK LIBRARIES

ANDROID RUNTIME

Phone

Package Manager

Telephony Manager

Location Manager

Notification Manager

Resource Manager

Surface Manager

Media Framework

SQLite

OpenGL/ES

FreeType

WebKit

SGL

SSL

Iibc

Activity Manager

Window Manager

View System

Dalvik Virtual Machine

Core Libraries

Content Providers

LINUX KERNEL

Keypad Driver

Wi-Fi Driver

Power Management

Audio Drivers

Display Driver

Camera Driver

Binder (IPC) Driver

Flash Memory Driver

FIGURE 1-

What Is Android? ❘ 7

have Motoblur, HTC devices have HTC Sense, and so on. However, the Nexus devices always run a clean version of Android with no modifications.

FIGURE 1-

The Android Market

As mentioned earlier, one of the main factors determining the success of a smartphone platform is the applications that support it. It is clear from the success of the iPhone that applications play a very vital role in determining whether a new platform swims or sinks. Also, making these applications accessible to the general user is extremely important. Users can simply use the Google Play application that is preinstalled on their Android devices to directly download third-party applications to their devices. Both paid and free applications are available in the Google Play Store, although paid applications are available only to users in certain countries because of legal issues.

NOTE Chapter 13 discusses more about Google Play Store and how you can sell your own applications in it.

8 ❘ CHAPTER 1 GETTING STARTED WITH ANDROID PROGRAMMING

OBTAINING THE REQUIRED TOOLS

Now that you know what Android is and what its feature set contains, you are probably anxious to get your hands dirty and start writing some applications! Before you write your fi rst app, however, you need to download the required tools. For Android development, you can use a Mac, a Windows PC, or a Linux machine. You can freely download all the necessary tools. Most of the examples provided in this book are written to work on Android Studio. For this book, I am using a Windows 10 computer to demonstrate all the code samples. If you are using a Mac or Linux computer, the screenshots should look similar. Some minor differences might be present, but you should be able to follow along without problems. Let the fun begin!

JAVA JDK 8

The Android Studio 2 makes use of the Java SE Development Kit 8 (JDK). If your computer does not have the JDK 8 installed, you should start by downloading it from www.oracle.com/technetwork/java/javase/downloads/jdk8- downloads-2133151.html and installing it prior to moving to the next section.

Android Studio The fi rst and most important piece of software you need to download is Android Studio 2. After you have downloaded and installed Android Studio 2, you can use the SDK Manager to download and install multiple versions of the Android SDK. Having multiple versions of the SDK available enables you to write programs that target different devices. For example, you can write one version of an application that specifically targets Android Nougat, but because that flavor of Android is on less than 1% of devices, with multiple versions of the SDK you can also write a version of your app that uses older features and targets Marshmallow or Lollipop users. You can use the Android Device Manager to set up device emulators. You can download Android Studio 2 from http://developer.android.com/sdk/index.html (see Figure 1-5). Android Studio 2 is packaged in an executable. Run the install process to set up Android Studio 2. After you’ve downloaded and run the setup executable, use the following steps to go through the installation process:

  1. Accept the terms and conditions shown in Figure 1-6.
  2. If you have an older version of Android Studio already installed on your computer, the Android Studio Setup prompts you to automatically uninstall it. Even though the old version of Android Studio will be uninstalled, the settings and configurations are retained. You have an opportunity to reapply those settings and configurations to Android Studio 2 after the setup has completed. Figure 1-7 shows the screen where you are prompted to uninstall an old version of Android Studio.

10 ❘ CHAPTER 1 GETTING STARTED WITH ANDROID PROGRAMMING

FIGURE 1-

  1. Click Next on the Welcome to Android Studio Setup screen (see Figure 1-8).

FIGURE 1-

  1. Pick which components of Android Studio you want to install from the screen shown in Figure 1-9. Android Studio is selected by default (and cannot be deselected), which makes sense given that you are going through all of this trouble for the distinct purpose of installing Android Studio. Android SDK and Android Virtual Device are also selected by default. Click Next to accept the default choices and continue.

Obtaining the Required Tools ❘ 11

FIGURE 1-

  1. You are presented with the License Agreement, as shown in Figure 1-10. Click I Agree to continue.

FIGURE 1-

  1. On the confi guration settings screen, it is best to accept the default locations specified by the setup process and click Next to continue. You see the Choose Start Menu Folder screen (shown in Figure 1-11). Click Install to kick off the Android Studio 2 installation.

Obtaining the Required Tools ❘ 13

  1. Android Studio 2 prompts you to either import settings from a previous version of Android Studio or continue with new settings. If you uninstalled a previous version in the first step of the installation process, Android Studio offers you a chance to recover the settings used in that previous version and apply them to Android Studio 2 (see Figure 1-13).

FIGURE 1-

Now that Android Studio 2 is installed, you need to adjust the settings and options using the following steps:

  1. Click Continue at the Welcome screen and choose Standard from the Install Type selection screen shown in Figure 1-14. Click Next to continue.

FIGURE 1-

14 ❘ CHAPTER 1 GETTING STARTED WITH ANDROID PROGRAMMING

  1. Click Finish on the Verify Settings screen, and Android Studio 2 finalizes the setup process. You know the process is complete when you are greeted with the Welcome to Android Studio screen (see Figure 1-15).

FIGURE 1-

Now that Android Studio is set up, it’s time to install the latest and greatest Android SDK.

Android SDK The most important piece of software you need to download is, of course, the Android SDK. The Android SDK contains all of the packages and tools required to develop a functional Android application. The SDKs are named after the version of Android OS to which they correspond. By default, the Marshmallow SDK was installed with Android Studio 2, which means you can develop applications that will run seamlessly on devices with Android Marshmallow. However, if you want to install a different Android SDK, you can do so using the SDK Manager from the Android Studio welcome screen (shown in Figure 1-15). From this screen, click the Configure drop-down menu in the lower-right corner. The Configure selection menu opens. Choose SDK Manager from this menu. The SDK configuration screen, shown in Figure 1-16, shows that the Marshmallow SDK is already installed. Android N is available to be installed (as of the writing of this book Android Nougat was in a fi nalized beta, so it might be named differently now).

16 ❘ CHAPTER 1 GETTING STARTED WITH ANDROID PROGRAMMING

You can create as many AVDs as you want to test your applications with different configurations. This testing is important to confi rm the behavior of your application when it is run on different devices with varying capabilities.

FIGURE 1-

Use the following steps to create an AVD. This example demonstrates creating an AVD (put simply, an Android emulator) that emulates an Android device running Android N on the Nexus 5x hardware specs.

  1. Start Android Studio so that the Welcome screen is visible (refer to Figure 1-15). Click Start a New Android Studio Project. You see the Create New Project Wizard shown in Figure 1-18.
  2. Set up a HelloWorld project (that you will use in the final section of this chapter). Type Chapter1Helloworld in the Application Name field.

Obtaining the Required Tools ❘ 17

FIGURE 1-

  1. You can keep the default values for the other fields on the New Project screen (they will be explained in more detail in later chapters). Click Next.

NOTE For the purposes of setting up a quick Hello World project and creating an AVD, you will be accepting many of the default values, without explanation, during the project setup process. This is fine for now, as all of the settings are explained in much greater detail in subsequent chapters.

  1. You should see the Targeted Android Devices screen. By default, the Create New Project Wizard selects for you the Android SDK level that has the greatest activity based on statis- tics gathered from Google Play. At the time this book was written 74.3 percent of the active devices on Google Play were written using Android Jelly Bean. For now, accept the default, as shown in Figure 1-19, and click Next.

  2. On the Add an Activity to Mobile screen, accept the default choice—Empty Activity (see Figure 1-20)—and click Next.

Obtaining the Required Tools ❘ 19

  1. Accept all of the defaults on the Customize the Activity screen, as shown in Figure 1-21, and click Finish. Figure 1-22 shows the open Android Studio IDE.

FIGURE 1-

FIGURE 1-

20 ❘ CHAPTER 1 GETTING STARTED WITH ANDROID PROGRAMMING

  1. Launch the AVD Manager by selecting Tools ➪ Android ➪ AVD Manager or using the AVD Manager button from the toolbar. Figure 1-23 shows the Android Virtual Device Manager Wizard, which is where you set up AVDs to be used when you emulate your application in Android on your desktop.

FIGURE 1-

  1. Click the + Create Virtual Device button to create a new AVD. The Virtual Device Configuration screen opens as shown in Figure 1-24.

  2. Select the Nexus 5x hardware profile and click Next. Although none of the emulators offers the same performance as its actual hardware counterpart, the Nexus 5x should run well on most x86-based desktops, and it still offers some of the mid- to high-end Android device specs.

  3. For the system image, select and install the latest option, which at the time this book was written is Android Nougat. Click the x86 Images tab (see Figure 1-25), select N from the list of images, and then click Next.