Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore CU-BCA-SEM-V-Mobile Application Development-Second Draft

CU-BCA-SEM-V-Mobile Application Development-Second Draft

Published by Teamlease Edtech Ltd (Amita Chitroda), 2022-02-26 01:58:23

Description: CU-BCA-SEM-V-Mobile Application Development-Second Draft

Search

Read the Text Version

BACHELOR OF COMPUTER APPLICATIONS SEMESTER-V MOBILE APPLICATION DEVELOPMENT

First Published in 2021 All rights reserved. No Part of this book may be reproduced or transmitted, in any form or by any means, without permission in writing from Chandigarh University. Any person who does any unauthorized act in relation to this book may be liable to criminal prosecution and civil claims for damages. This book is meant for educational and learning purpose. The authors of the book has/have taken all reasonable care to ensure that the contents of the book do not violate any existing copyright or other intellectual property rights of any person in any manner whatsoever. In the event, Authors has/ have been unable to track any source and if any copyright has been inadvertently infringed, please notify the publisher in writing for corrective action. 2 CU IDOL SELF LEARNING MATERIAL (SLM)

CONTENT Unit 1: Core Java Concepts........................................................................................................4 Unit 2: Introduction To Android Part 1 ...................................................................................23 Unit 3: Introduction To Android Part 2 ...................................................................................42 Unit 4: Android Project Structure ............................................................................................64 Unit 5: Android View Part 1....................................................................................................85 Unit 6: Android View Part 2..................................................................................................107 Unit 7: Android View Part 3..................................................................................................133 Unit 8: Other Android Components.......................................................................................160 Unit 9: Android Fragments ....................................................................................................183 Unit 10: Android Menus ........................................................................................................205 Unit 11: Database Connectivity .............................................................................................226 Unit 12: Deployment..............................................................................................................249 3 CU IDOL SELF LEARNING MATERIAL (SLM)

UNIT 1: CORE JAVA CONCEPTS 4 STRUCTURE 1.0 Learning Objectives 1.1 Introduction 1.2 Class & Objects 1.3 Getters and Setters 1.3.1 What are Getter and Setter? 1.3.2 Why Getter and Setter? 1.3.3 Naming Convention for Getter and Setter 1.3.4 Common Mistakes When Implementing Getter and Setter 1.3.5Implementing Getters and Setters for Primitive Types 1.3.6Implementing Getters and Setters for Common Object Types 1.3.7Implementing Getters and Setters for Collection Type 1.3.8Implementing Getters and Setters for Your Own Type 1.4Java Collections 1.4.1 Overview 1.4.2 Array List in Java 1.4.3 Array List Class Methods 1.4.4 Difference between Array List and HashMap in Java 1.5 Summary 1.6 Keywords 1.7 Learning Activity 1.8 Unit End Questions 1.9 References 1.0 LEARNING OBJECTIVES After studying this unit, you will be able to:  Describe the basics of Class & Objects.  State the Difference between Array List and HashMap in Java. CU IDOL SELF LEARNING MATERIAL (SLM)

 Describe the Array List in Java.  Identify the Common mistakes when implementing getter and setter.  Explain getter and setter.  Explain Java Collections. 1.1 INTRODUCTION JAVA was developed by James Gosling at Sun Microsystems Inc in the year 1991, later acquired by Oracle Corporation. It is a simple programming language. Java makes writing, compiling, and debugging programming easy. It helps to create reusable code and modular programs. Java is a class-based, object-oriented programming language and is designed to have as few implementation dependencies as possible. A general-purpose programming language made for developers to write once run anywhere that is compiled Java code can run on all platforms that support Java. Java applications are compiled to byte code that can run on any Java Virtual Machine. The syntax of Java is likeC/C++. After the name OAK, the team decided to give a new name to it and the suggested words were Silk, Jolt, revolutionary, DNA, dynamic, etc. These all names were easy to spell and fun to say, but they all wanted the name to reflect the essence of technology. In accordance with James Gosling, Java is in the top names along with Silk, and since java was a unique name so most of them preferred it. Java is the name of an island in Indonesia where the first coffee was produced. And this name was chosen by James Gosling while having coffee near his office. Note that Java is just a name, not an acronym. Java is a true object-oriented programming language. The main implication of this statement is that to write programs with Java, you must work within its object-oriented structure. Object-oriented languages provide a framework for designing programs that represent real- world entities such as cars, employees, insurance policies, and so on. Representing real-world entities with non-object-oriented languages is difficult because it's necessary to describe entities such as a truck with rather primitive language constructs such as Pascal's record, C's and data only. The behaviour of an entity must be handled separately with language constructs such as procedures and/or functions, hence, the term procedural programming languages. Given and others that represent this separation, the programmer must manually associate a data structure with the appropriate procedures that operate on, that is, manipulate, the data. In contrast, object-oriented languages provide a more powerful class construct for representing user-defined entities. The class construct supports the creation of user-defined data types, such as Employee, that represent both the data that describes a particular 5 CU IDOL SELF LEARNING MATERIAL (SLM)

employee and the manipulation or use of that data. Java programs employ user-defined data types liberally. Designing nontrivial Java classes requires, of course a good working knowledge of Java syntax. 1.2 CLASS & OBJECTS Java is an Object-Oriented Language. As a language that has the Object-Oriented feature, Java supports the following fundamental concepts:  Polymorphism  Inheritance  Encapsulation  Abstraction  Classes  Objects  Instance  Method  Message Parsing In this chapter, we will look into the concepts - Classes and Objects.  Object - Objects have states and behaviours. Example: A dog has states - colour, name, breed as well as behaviours wagging the tail, barking, eating. An object is an instance of a class.  Class - A class can be defined as a template/blueprint that describes the behaviour. Objects in Java Let us now look deep into what are objects. If we consider the real-world, we can find many objects around us, cars, dogs, humans, etc. All these objects have a state and behaviour. If we consider a dog, then its state is name, breed, colour, and the behaviourare barking, wagging the tail, running. If you compare the software object with a real-world object, they have very similar characteristics. Software objects also have a state and behaviour. A software object's state is stored in fields and behaviour is shown via methods. So, in software development, methods operate on the internal state of an object and the object-to-object communication is done via methods. 6 CU IDOL SELF LEARNING MATERIAL (SLM)

Classes in Java A class is a blueprint from which individual objects are created. Following is a sample of a class.Public class Dog- Void barking Void hungry Void sleeping A class can contain any of the following variable types.  Local variables: Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.  Instance variables: Instance variables are variables within a class but outside any method. These variables are initialized when the class is instantiated. Instance variables can be accessed from inside any method, constructor or blocks of that class.  Class variables: Class variables are variables declared within a class, outside any method, with the static keyword. A class can have any number of methods to access the value of various kinds of methods. In the above example, barking, hungry and sleeping are methods. 1.3 GETTERS AND SETTERS Getters and setters are used to protect your data, particularly when creating classes. For each instance variable, a getter method returns its value while a setter method sets or updates its value. Given this, getters and setters are also known as matadors, respectively. By convention, getters start with the word \"get\" and setters with the word \"set\", followed by a variable name. In both cases the first letter of the variable's name is capitalized. 1.3.1 What are Getter and Setter? In Java, getter and setter are two conventional methods that are used for retrieving and updating the value of a variable. The following code is an example of a simple class with a private variable and a couple of getter/setter methods: 1 Public class Simple 2 Private INT number 7 CU IDOL SELF LEARNING MATERIAL (SLM)

3 Public INT get Number 4 Return this. number 5 Public void setNumber Table 1.1: Getter and setter The class declares a private variable, number. Since number is private, the code from the outside of this class cannot access the variable directly, as shown below: 1. Simple GetterandSetter OBJ = new SimpleGetterAnd Setter 2. OBJ. Number = 10; // compile error, since number is private 3. INT num = OBJ number; // same as above So, a setter is a method that updates the value of a variable. And a getter is a method that reads the value of a variable. Getter and setter are also known asACCESSORandMUTATORin Java. 1.3.2 Why Getter and Setter? By using getter and setter, the programmer can control how their important variables are accessed and updated in the proper manner, such as changing the value of a variable within a specified range. Figure1.1: Why getter and setter So far, the setter and getter methods protect a variable’s value from unexpected changes by the outside world the caller code. When a variable is hidden by the private modifier and can be accessed only through getter and setter, it is encapsulated. Encapsulation is one of the fundamental principles in object- oriented programming, thus implementing getter and setter is one of the ways to enforce encapsulation in the program’s code. Some frameworks such as Hibernate, spring, and Struts can inspect information or inject their utility code through getter and setter. So, providing getter and setter is necessary when integrating your code with such frameworks. 8 CU IDOL SELF LEARNING MATERIAL (SLM)

1.3.3 Naming Convention for Getter and Setter The naming scheme of setter and getter should follow the Java bean naming convention as get and set, where the name of the variable is. The following table shows some examples of getters and setters which qualified for the naming convention: Variable declaration Getter method Setter method INT quantity INT get Quantity void setQuantity String firstName String get First Name void setFirstName Date birthday Date getBirthday void setBirthday Boolean rich Boolean is Rich void set Rich Table 1.2: Naming convention for getter and setter 1.3.4 Common Mistakes when Implementing Getter and Setter People often make mistakes, and developers are no exception. This section describes the most common mistakes when implementing setters and getters in Java, as well as workarounds. Mistake #1: Have setter and getter, but the variable is declared in less restricted scope. The variable firstName is declared as public, so it can be accessed using dot (.) operator directly, making the setter and getter useless. Workaround for this case is using more restricted access modifier such as protected and private: 9 CU IDOL SELF LEARNING MATERIAL (SLM)

Figure 1.2: Mistake #1 The variable firstName is declared as public, so it can be accessed using dot (.) operator directly, making the setter and getter useless. Workaround for this case is using more restricted access modifier such as protected and private: 1Private String first Name. In the book Effective Java, Joshua Bloch points out this problem in the item 14: In public classes, use access or methods, not public fields. Mistake 2: Assign object reference directly in the setter Considering the following setter method: Private INT [] scores; Public void set Scores(in [] SCR) This. scores = SCR; And following is code that demonstrates the problem: 1. INT [] my Scores = {5, 5, 4, 3, 2, 4}; 2. Set Scores(my Scores); 3. Display Scores(); 4. Display Scores(); Mistake 3: Return the object reference directly in getter Do not return a reference of the original object in the getter method. Instead, it should return a copy of the original object. Consider the following getter method: 1. Private INT[] scores 2. Public INT[] get Scores 3. Return this. scores; And the following code snippet: 10 CU IDOL SELF LEARNING MATERIAL (SLM)

Consider the following getter method: 1. Private INT [] scores; 2. Public INT [] get Scores 3. Return this. scores And the following code snippet: 1.INT [] my Scores = {5, 5, 4, 3, 2, 4}; 2. set Scores(my Scores); 3. display Scores(); 4. INT [] copy Scores = get Scores(); 5. copy Scores[1] = 1; 6. display Scores(); It will produce the following output: 1 5 54324 2 5 14324 As you notice, the 2nd element of the array scores is modified outside the setter, at line 5. Because the getter method returns reference of the internal variable scores directly, so the outside code can obtain this reference and makes change to the internal object. Workaround for this case is that, instead of returning the reference directly in the getter, we should return a copy of the object, so the outside code can obtain only a copy, not the internal object. Therefore we modify the above getter as follows: 1. Public INT get Scores 2. INT [] copy = new INT 3. System array copy 4. Return copy; So, the rule of thumb is do not return reference of the original object in getter method. Instead, it should return a copy of the original object. 1.3.5 Implementing Getters and Setters for Primitive Types With primitive types you can freely assign/return values directly in setter/getter because Java copies the value of one primitive to another instead of copying the object reference. So, mistakes #2 and #3 can easily be avoided. 11 CU IDOL SELF LEARNING MATERIAL (SLM)

For example, the following code is safe because the setter and getter involve in a primitive type of float: 1. Private float amount; 2. Public void set Amount 3. This. amount = amount; 4. Public float get Amount 5. Return this. amoun So, for primitive types, there is no special trick to correctly implement the getter and setter. 1.3.6 Implementing Getters and Setters for Common Object Types Getters and Setters for String objects String is an object type, but it is immutable which means once a String object is created, its String literal cannot be changed. In other words, every change on that String object will result in a new String object created. So, like primitive types, you can safely implement getter and setter for a String variable like this: 1. Private String address; 2. Public void set Address 3. This. address = address 4. public String get Address 5. Return this. address; Getters and Setters for Date objects Thejava until Dateclass implementsclonemethod from theObjectclass. The methodclonereturns a copy of the object, so we can use it for the getter and setter, like the following example: 1. Private Date birth Date; 2. Public void set Birth Date 3. This. birth Date = (Date) 4. Public Date get Birth Date 5. Return (Date) this. Birth Date. Clone(); Theclone method returns an Object, so we must cast it to Date type. 12 CU IDOL SELF LEARNING MATERIAL (SLM)

1.3.7 Implementing Getters and Setters for Collection Type As described in mistake #2 and mistake #3, it’s not good to have setter and getter methods like this: 1. Private List<String> list Titles; 2. Public void set List Titles (List<String>titles) 3. This. list Titles = titles; 4. Public List<String> get List Titles 5. Return this. list Titles; According to the rules for implementing getter and setter the three system out print in statements should produce the same result. However, when running the above program it produces the followingoutput: 1. Titles 1: [Name, Address, Email, Job] 2. Titles 2: [Name, Address, Facilitation, Job] 3. Titles 3: [Full name, Address, Facilitation, Job] That means the collection can be modified from code outside of the getter and setter. For a collection of Strings, one solution is to use the constructor that takes another collection as argument, for example we can change code of the above getter and setter as follows: 1. Public void set List Titles (List<String> titles) 2. This. list Titles = new Array List<String>(titles) 3. public List<String> get List Titles 4. return new Array List<String>(this list Titles) Re-compile and run the CollectionGetterSetter program, it will produce desired output: 1.Titles 1: [Name, Address, Email, Job] 2. Titles 2: [Name, Address, Email, Job] 3. Titles 3: [Name, Address, Email, Job] Because unlike String which new objects will be created whenever a String object is copied, other Object types are not. Only references are copied, so that’s why two collections are distinct but they contain same objects. In other words, it is because we haven’t provided any mean for copying objects. Look at the collection API we found that ArrayList, HashMap, Hash Set implement their own clone methods, these methods return shallow copies which do not copy elements from 13 CU IDOL SELF LEARNING MATERIAL (SLM)

the source collection to the destination. According to Java doc of the clone method of ArrayList class: So key points for implementing getter and setter for collection type are:  For collection of String objects: does not need any special tweak since String objects are immutable.  For collection of custom types of object:  Implement clone method for the custom type.  For the setter, add cloned items from source collection to the destination one.  For the getter, create a new collection which is being returned. Add cloned items from the original collection to the new one. 1.3.8 Implementing Getters and Setters for your own Type If you define a custom type of object, you should implement clone method for your own type. For example: 1. Class Person 2. Private String name 3. Public Person (String name) 4. This.name = name 5. Public String get Name 6. Return this.name 7. Public void set Name(String name) 8. This name = name 9. Public String to String 10. Return this.name 11. Public Object clone 12. Person a Clone = new Person(this.name) 13. Return a Clone So, the rules for implementing getter and setter for a custom object type are: 14  Implement clone method for the custom type. CU IDOL SELF LEARNING MATERIAL (SLM)

 Return a cloned object from the getter.  Assign a cloned object in the setter. 1.4 JAVA COLLECTIONS (ARRAY LIST AND HASHMAP) ArrayList is a part of collection framework and is present in java util package. It provides us dynamic arrays in Java. Though, it may be slower than standard arrays but can be helpful in programs where lots of manipulation in the array is needed. HashMap is a part of Java’s collection since Java 1.2. It provides the basic implementation of Map interface of Java. It stores the data in pairs. To access a value, one must know its key. HashMap is known as HashMap because it uses a technique called Hashing. Hashing is a technique of converting a large String to small String that represents same String. A shorter value helps in indexing and faster searches. HashSet also uses HashMap internally. It internally uses a link list to store key-value pairs already explained in HashSet in detail and further articles. 1.4.1 Overview The following figure demonstrates the Java Collection framework. Figure 1.3 Java collection frameworks Of these I shall discuss the following:  ArrayList  HashMap First, we will understand each of them, their respective classes and methods. Then we shall try out examples for each type. 15 CU IDOL SELF LEARNING MATERIAL (SLM)

1.4.2 Array List in Java ArrayList is a collection API used for storing elements using dynamic array. The dynamic array is an array in which the array size is not fixed in advance. Therefore, we can change the size of an array at run time using the ArrayList class. When we store elements into ArrayList, depending on the number of elements, the memory is allotted and re-allotted to accommodate all the elements. Every instance of the ArrayList class is allowed to store a set of elements in the list. Some of the important points about ArrayList class shown below:  ArrayList is not synchronized.  ArrayList supports dynamic array which can grow as needed.  Size of ArrayList can be dynamically increased or decreased.  ArrayLists are created with initial size.  In Java, standard arrays are of fixed length. After arrays are created, they cannot grow or shrink means you must know in advance how many elements an array will hold.  ArrayList can contain duplicate elements.  ArrayList maintains insertion order of the elements.  Retrieval is random access because array works at index basis. 1.4.3 Array List Class Methods Method Description void add It inserts specified element at the specified position in the ArrayList. Boolean add It appends specified element to the end of the ArrayList. Boolean It appends all the elements of the collection to the end of the ArrayList. addAll element It removes specified element at the specified position in the ArrayList. remove Boolean It removes first occurrence of specified element OBJ from the ArrayList. remove 16 CU IDOL SELF LEARNING MATERIAL (SLM)

void clear It removes all the elements from the ArrayList. Boolean It returns true if ArrayList contains the specified element. contains object get It returns the element at the specified position in the ArrayList. It returns first occurrence of the specified element in the list or -1 if element INT indexOf not found in the list. INT It returns the last occurrence of the specified element in the list or -1 if the lastIndexOf element is not found in the list. INT size It returns the number of elements in the list. Table:1.3 Array list 1.4.4 Difference between Array List and HashMap in Java ArrayList HashMap ArrayList implements the List interface. HashMap implements the Map interface. ArrayList implements the List interface. HashMap implements the Map interface. ArrayList stores element's value and HashMap stores elements key & value pair. For maintains the indexes for each element. each value, there must be a key associated with HashMap. ArrayList stores only a single object. HashMap stores elements in Key and value pairs. We get the element by specifying the The elements are being fetched by the 17 CU IDOL SELF LEARNING MATERIAL (SLM)

index of it in ArrayList. corresponding Key in HashMap. The ArrayList maintains the order of the HashMap does not provide a guarantee of the objects they are inserted. order in which they are inserted. ArrayList allows duplicate elements. HashMap allows duplicate values but does not allow duplicate keys. The ArrayList always The Hash Map get method has O (1) time gives O(1)performance in best case or complexity in the best case and O (n) time worst-case time complexity. complexity in worst case. ArrayList has any number of null HashMap allows only one null Key and lots of elements. null values. ArrayList is the index-based data structure While HashMap is a mapped data structure that supported by the array. works on hashing to obtain stored values. Table:1.4Array list and hash map 1.5 SUMMARY  Java is a class-based, object-oriented programming language and is designed to have as few implementation dependencies as possible. A general-purpose programming language made for developers to write once run anywhere that is compiled Java code can run on all platforms that support Java. Java applications are compiled to byte code that can run on any Java Virtual Machine. The syntax of Java is likeC/C++.Training has many aspects.  In Java, getter and setter are two conventional methods that are used for retrieving and updating the value of a variable.  By using getter and setter, the programmer can control how their important variables are accessed and updated in the proper manner, such as changing the value of a variable within a specified range. 18 CU IDOL SELF LEARNING MATERIAL (SLM)

 In Java, getter and setter are two conventional methods that are used for retrieving and updating the value of a variable.  People often make mistakes, and developers are no exception. This section describes the most common mistakes when implementing setters and getters in Java, as well as workarounds  The naming scheme of setter and getter should follow the Java bean naming convention as get and set, where Xxx is the name of the variable.  Some frameworks such as Hibernate, spring, and Struts can inspect information or inject their utility code through getter and setter. So, providing getter and setter is necessary when integrating your code with such frameworks. 1.6 KEYWORDS  Collection in Java is a framework that provides architecture to store and manipulate the group of objects. Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.  Instance variables are variables within a class but outside any method. These variables are initialized when the class is instantiated. Instance variables can be accessed from inside any method, constructor or blocks of that class.  ArrayList is a collection API used for storing elements using dynamic array. The dynamic array is an array in which the array size is not fixed in advance. Therefore, we can change the size of an array at run time using the ArrayList class.  getter and setter are two conventional methods that are used for retrieving and updating the value of a variable  Java is a class-based, object-oriented programming language and is designed to have as few implementation dependencies as possible. A general-purpose programming language made for developers to write once run anywhere that is compiled Java code can run on all platforms that support Java. Java applications are compiled to byte code that can run on any Java Virtual Machine. The syntax of Java is like c/c++. 1.7 LEARNING ACTIVITY 1. Find How to run Java program in Mobile. ___________________________________________________________________________ __________________________________________________________________________ 2. Draw aJava Collection Framework in your Note book. 19 CU IDOL SELF LEARNING MATERIAL (SLM)

___________________________________________________________________________ __________________________________________________________________________ 1.8 UNIT END QUESTIONS A. Descriptive Questions Short Questions 1. Define Java? 2. What are getter and setter? 3. Why getter and setter? 4. What isArray List in Java? 5. What is HashMap in Java? Long Questions 1. What is Array List in Java? Explain Array List Class Methods? 2. Describe the Class & Objects. 3. What is the Difference between Array List and HashMap in Java? 4. Describe about Implementing getters and setters for collection type. 5. Explain Common mistakes when implementing getter and setter. B. Multiple Choice Questions 1. Which of this class is superclass of every class in Java? a. String class b. Object class c. Abstract class d. ArrayList class 2. Which of these methods of Object class can clone an object? a. Objectcopy b. copy c. Object clone d. Clone 3. Which of the following option leads to the portability and security of Java? 20 a. Bytecode is executed by JVM CU IDOL SELF LEARNING MATERIAL (SLM)

b. The applet makes the Java code secure and portable c. Use of exception handling d. Dynamic binding between objects 4. Which of the following is not a Java features? a. Dynamic b. Architecture Neutral c. Use of pointers d. Object-oriented 5. What is used to find and fix bugs in the Java programs. a. JVM b. JRE c. JDK d. JDB Answers 1-b, 2- c, 3-a, 4- c, 5- d 1.9 REFERENCES Reference  Zigurd Mednieks, Laird Dornin, Blake Meike G, and Masumi Nakamura, 2011,“Programming Android”, O’Reilly books,  Sahni, Sartaj, Data Structures, Algorithms, & Application in Java.MGH  Joshua Bloch, 2008, Effective Java, 3rd Edition Textbooks  Reto Meier,2012. Professional Android 4 Application Development”, John Wiley & Sons, Inc,  C. S/ Cornell, G. 2008.Core Java: Volume I – Fundamentals Horstmann, 8th ed. Pearson  Wei -Meng Le, 2012.Beginning Android 4 Application Development”, John Wiley & Sons, Inc. 21 CU IDOL SELF LEARNING MATERIAL (SLM)

Websites  https://www.tutorialspoint.com/  https://www.javatpoint.com/  https://dzone.com  https://www.java.com/ 22 CU IDOL SELF LEARNING MATERIAL (SLM)

UNIT 2: INTRODUCTION TO ANDROID PART 1 STRUCTURE 2.0 Learning Objectives 2.1 Introduction 2.2 Android and its Versions 2.2.1 What Is Android? 2.2.2 Android Versions 2.2.3 Features of Android 2.2.4 Android Devices in the Market 2.2.5 The Android Market 2.2.6 The Android Developer Community 2.3 Android Architecture 2.4 Summary 2.5 Keywords 2.6 Learning Activity 2.7 Unit End Questions 2.8 References 2.0 LEARNING OBJECTIVES After studying this unit, you will be able to:  Explain Android.  Outline the Android Devices in the Market.  Describe Android Versions.  Explain the Features of Android.  Explain Android Architecture.  Describe the Android Developer Community. 23 CU IDOL SELF LEARNING MATERIAL (SLM)

2.1 INTRODUCTION Welcome to the world of Android! When I was writing my first book on Android, I stated that Android was ranked second in the U.S. Smartphone market, second to Research in Motion’s BlackBerry, and overtaking Apple’s phone. Shortly after the book went to press, comScore reported that Android has overtaken BlackBerry as the most popular smartphone platform in the U.S. A few months later, Google released Android 3.0, code named Honeycomb. With Android 3.0, Google’s focus in the new Software Development Kit was the introduction of several new features designed for widescreen devices, specifically tablets. If you are writing apps for Android smartphones, Android 3.0 is not useful, as the new features are not supported on smartphones. While Android 3.0 was released, Google began working on the next version of Android, which can be used on both smartphones and tablets. In October 2011, Google released Android 4.0, code named Ice Cream Sandwich, and that is the focus of this book. In this chapter you will learn what Android is, and what makes it so compelling to both developers and device manufacturers alike. You will also get started with developing your first Android application, and learn how to obtain all the necessary tools and set them up so that you can test your application on an Android 4.0 emulator. 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. Whether you’re an experienced mobile engineer, a desktop or web developer, or a complete programming novice, Android represents an exciting new opportunity to write innovative applications for an increasingly wide range of devices. Despite the name, Android will not help you create an unstoppable army of emotionless robot warriors on a relentless quest to cleanse the earth of the scourge of humanity. Instead, Android is an open-source software stack that includes the operating system, middleware, and key mobile applications, along with a set of API libraries for writing applications that can shape the look, feel, and function of the devices on which they run. Small, stylish, and versatile, modern mobile devices have become powerful tools that incorporate touchscreens, cameras, media players, Global Positioning System receivers, and Near Field Communications (NFC) hardware. As technology has evolved, mobile phones have become about much more than simply making calls. With the introduction of tablets and Google TV, Android has expanded beyond its roots as a mobile phone operating system, providing a consistent platform for application development across an increasingly wide range of hardware. In Android, native, and third- party applications are written with the same APIs and executed on the same run time. These APIs feature hardware access, video recording, location-based services, support for background services, map-based activities, relational databases, inter-application communication, Bluetooth, NFC, and 2D and 3D graphics. This book describes how to use these APIs to create your own Android applications. In this chapter you’ll learn some guidelines for mobile and embedded hardware development, as well as be introduced to some 24 CU IDOL SELF LEARNING MATERIAL (SLM)

of the platform features available for Android development. Android has powerful APIs, excellent documentation, a thriving developer community, and no development or distribution costs. As mobile devices continue to increase in popularity, and Android devices expand into exciting new form-factors, you can create innovative applications no matter what your development experience 2.2 ANDROID AND ITS VERSIONS 2.2.1 What is Android? Android is a mobile operating system that is based on a modified version of Linux. It was originally developed by a start-up of the same name, Android, Inc. In 2005, as part of its strategy to enter the mobile space, Google purchased Android and took over its development work Google wanted Android to be open and free; hence, most of the Android code was released under the open source Apache License, which means that anyone who wants to use Android can do so by downloading the full Android source code. Moreover, vendors can add their own proprietary extensions to Android and customize Android to differentiate their products from others. This simple development model makes Android very attractive and has thus piqued the interest of many vendors. This has been especially true for companies affected by the phenomenon of Apple’s Phone, a hugely successful product that revolutionized the smartphone industry. Such companies include Motorola and Sony Ericsson, which for many years have been developing their own mobile operating systems. When the Phone was launched, many of these manufacturers had to scramble to find new ways of revitalizing their products. These manufacturers see Android as a solution they will continue to design their own hardware and use Android as the operating system that powers it. The main advantage of adopting Android is that it offers a unified approach to application development. Developers need only develop for Android, and their applications should be able to run on numerous different devices, if the devices are powered using Android. In the world of smartphones, applications are the most important part of the success chain. Device manufacturers therefore see Android as their best hope to challenge the onslaught of the phone, which already commands a large base of applications. Android is a mobile operating system based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. Android is developed by a consortium of developers known as the Open Handset Alliance and commercially sponsored by Google. It was unveiled in November 2007, with the first commercial Android device, the HTC Dream, being launched in September 2008. It is free and open-source software; its source code is known as Android Open Source Project (AOSP), which is primarily licensed under the Apache License. However most Android devices ship with additional proprietary software pre-installed, most notably Google Mobile 25 CU IDOL SELF LEARNING MATERIAL (SLM)

Services which includes core apps such as Google Chrome, the digital distribution platform Google Play, and associated Google Play Services development platform. Competing Android ecosystems and forks include Fire OS or LineageOS. However, the \"Android\" name and logo are trademarks of Google which impose standards to restrict \"uncertified\" devices outside their ecosystem to use android branding. The source code has been used to develop variants of Android on a range of other electronics, such as game consoles, digital cameras, portable media players, PCs, and others, each with a specialized user interface. Some well-known derivatives include Android TV for televisions and Wear OS for wearable’s, both developed by Google. Software packages on Android, which use the APK format, are generally distributed through proprietary application stores like Google Play Store, Samsung Galaxy Store, Hawaii AppGallery, Cafe Bazaar, and GetJar, or open source platforms like F-Droid. Android has been the best-selling OS worldwide on smartphones since 2011 and on tablets since 2013. As of May 2021, it has over three billion monthly active users, the largest installed base of any operating system, and as of January 2021, the Google Play Store features over 3 million apps. The current stable version is Android 11, released on September 8, 2020. 2.2.2 Android Versions Android 1.0 To compete with Apple’s IOS, Android introduced its Android 1.0 in 2008. The version then was nothing as compared to what we use today. The interface was pretty basic and there were not many features. However, the first release of the Android version has the basic Google Apps that we use. This includes Maps, Calendar, Gmail, and YouTube, etc. Android 1.5 Cup-cake With the second public release of Android, they started naming the versions. The introduction of Android Cupcake brought some major changes to the operating systems. There was an option to capture videos along with photos. The widgets were now open for third-party developers. Also, this version brought up the on-screen keyboard. Android 1.6 Donut The Android 1.6 Donut was introduced to make the interface user-friendly and better than before. Google wanted to make the availability of this OS worldwide. This upgrade brought in the support for mobile networks such as Sprint and Verizon. The most remarkable feature was the search box that we see in the latest versions too. Android 2.0 Éclair 26 CU IDOL SELF LEARNING MATERIAL (SLM)

Within one year, Android has released three major upgrades with the Android 2.0 Éclair release. The Maps featured a voice navigation system that was a big deal back then. Another amazing upgrade was with the internet browser. They have introduced the support for HTML5 that makes playing videos easier on the browsers. Android 2.2 FROYO The 2.2FROYO upgrade in 2010 was a turning point for Android. The first Nexus phone was introduced to the world that changed the game of smartphones. This version refined the Android experience. The home screen panel now has a total of five panels instead of just three. The Gallery application’s design was revamped with new features. The major change was the PIN lock system along with the support for Mobile Hotspot. Android 2.3 Gingerbread The next generation of Android debuted with the Nexus S named as Gingerbread. The software had a better home screen design and widgets that were more user-friendly than before. The keyboard was integrated with the support for Multi touch. This upgrade changed the game ofselfless with the introduction of support for the front-facing camera. Android 3.0 Honeycomb The Android Honeycomb was structured to run on tablets too. The classic green theme of the interface got replaced with hues of blue. The widgets can be customised a little according to the user’s need. The most remarkable feature of 3.0 was virtual buttons. The need to use physical buttons was pulled out. Android 4.0 Ice-Cream Sandwich In the same year, Android released the next upgrade. This was released with the introduction of Samsung Galaxy Nexus with features integrated from Honeycomb. Along with that, a few more options were added to the interface. This included facial recognition, data usage analysis and new interfaces for Calendar and Mail apps. Android 4.1 Jelly Bean In the following year, Jelly Bean upgrade was about to change the market of smartphones. This was where the ear of Google’s OS started. A swipe to see feature could now get you weather updates, notifications of email and calendar reports on a single screen. Expandable notifications, flexible fonts and customisable widgets changed the way people have used Android till 2012. Android 4.4 KitKat With the launch of Nexus 5, Google introduced Android 4.4 KitKat that modernised the interface. A lighter colour theme was introduced for the OS and applications too. The ‘OK 27 CU IDOL SELF LEARNING MATERIAL (SLM)

Google’ search command was revealed. A new phone dialler, full-screen app support and Hangouts app was introduced for efficient messaging and calling. Android 5.0 Lollipop With the Lollipop version, Android introduced the material design theme in the interface. The pull-down notification screen was improved with widget collection. The support for RAW image files was added to the system. The Android TV was also revealed to be used with televisions that too changed the game of our modern TV experience. Android 6.0 Marshmallow With a white app’s menu screen and a handy search bar at the top, Android revealed the Marshmallow. The option for memory management was introduced to the users. The volume control panel was introduced that comes in really handy to use even today. However, the notable upgrade in 2015 was the support for fingerprint scanners. Android 7.0 Nougat After 10 years of the launch, Nougat was the biggest upgrade to Android. The notification panel was improved with grouped notifications. The multitaskingcapabilities of the system were improved by offering the split-screen mode. Google Now got replaced with Google Assistant making our online searching experience easier than ever. Android 8.0 Oreo The Oreo upgrade was pretty interesting with the introduction of Picture-in-Picture mode. The PIP mode and split-screen mode changed the game of multitasking for the users. The notification panel now had the options to snooze notifications and can be sorted by various categories. Android 9.0 Pie The virtual buttons that we’ve been using in Android devices were now replaced with a single virtual button. The feature of ‘Digital Wellbeing’ was introduced to make sure you don’t spend unnecessary hours on your phone. Adaptive Battery and App Actions were also revealed to manage background app processes. Android 10 A brand-new logo with better colours was revealed to rebrand the Android OS. No new names are going to arrive for Android versions. We will be seeing only numbers with the upcoming versions. Navigation buttons are replaced with gestures to make usage easier and better. The most loved feature of Android 10 was the ‘Dark Mode’ that helps to save battery and looks better to our eyes. Android 11 28 CU IDOL SELF LEARNING MATERIAL (SLM)

Google has released its latest big update called Android 11 “R”, which is rolling out now to the firm's Pixel devices and to smartphones from a handful of third-party manufacturers.09- Sep-2020 2.2.3 Features of Android Because Android is open source and freely available to manufacturers for customization, there is no fixed hardware or software configurations, However, Android itself supports the following features: Sr. No. Feature & Description 1 Beautiful UI Android OS basic screen provides a beautiful and intuitive user interface. 2 Connectivity GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi, LTE, NFC and WIMAX. 3 Storage SQ LITE a lightweight relational database, is used for data storage purposes. 4 Media support H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC, AAC 5.1, MP3, MIDI, WAV, JPEG, PNG, GIF, and BMP. 5 Messaging SMS and MMS 6 Web browser Based on the open-source WebKit layout engine, coupled with Chrome's V8 29 CU IDOL SELF LEARNING MATERIAL (SLM)

JavaScript engine supporting HTML5 and CSS3. 7 Multi-touch Android has native support for multi-touch which was initially made available in handsets such as the HTC Hero. 8 Multi-tasking User can jump from one task to another and same time various application can run simultaneously. 9 Resizable widgets Widgets are resizable, so users can expand them to show more content or shrink them to save space. 10 Multi-Language Supports single direction and bi-directional text. 11 GCM Google Cloud Messaging (GCM) is a service that lets developers send short message data to their users on Android devices, without needing a proprietary sync solution. 12 Wi-Fi Direct A technology that lets apps discover and pair directly, over a high-bandwidth peer-to-peer connection. 13 Android Beam A popular NFC-based technology that lets users instantly share, just by touching two NFC-enabled phones together. 30 CU IDOL SELF LEARNING MATERIAL (SLM)

Table 2.1: Features of android 2.2.4 Android Devices in the Market Android devices come in all shapes and sizes the Android OS powers the Following types of devices:  Smartphones  Tablets  E-reader devices  Netbooks  MP4 players  Internet TVs Smartphone A smartphone is a cellular telephone with an integrated computer and other features not originally associated with telephones such as an operating system, web browsing, and the ability to run software applications. A smartphone is a portable device that combines mobile telephone and computing functions into one unit. They are distinguished from feature phones by their stronger hardware capabilities and extensive mobile operating systems, which facilitate wider software, internet, and multimedia functionality, alongside core phone functions such as voice calls and text messaging. Smartphones typically contain several metal–oxide–semiconductor integrated circuit chips, include various sensors that can be leveraged by pre-included and third-party software, and support wireless communications protocols. Early smartphones were marketed primarily towards the enterprise market, attempting to bridge the functionality of standalone personal digital assistant devices with support for cellular telephony, but were limited by their bulky form, short battery life, slow ANALOG cellular networks, and the immaturity of wireless data services. These issues were eventually resolved with the exponential scaling and miniaturization of MOS transistors down to sub- micron levels the improved lithium-ion battery, faster digital mobile data networks and more mature software platforms that allowed mobile device ecosystems to develop independently of data providers. In the 2000s, NTT DOCOMO's I-mode platform, BlackBerry, Nokia's platform, and Windows Mobile began to gain market traction, with models often featuring QWERTY keyboards or resistive touchscreen input and emphasizing access to push email and wireless internet. Following the rising popularity of the phone in the late 2000s, most smartphones have featured thin, slate-like form factors, with large, capacitive screens with support for 31 CU IDOL SELF LEARNING MATERIAL (SLM)

multi-touch gestures rather than physical keyboards and offer the ability for users to download or purchase additional applications from a centralized store, and use cloud storage and synchronization, virtual assistants, as well as mobile payment services. Smartphones have largely replaced PDAs and handheld/palm-sized PCs. Improved hardware and faster wireless communication (due to standards such as LTE) have bolstered the growth of the smartphone industry. In the third quarter of 2012, one billion smartphones were in use worldwide. Global smartphone sales surpassed the sales figures for feature phones in early 2013. Tablets A tablet is a wireless touch screen personal computer that is smaller than a notebook but larger than a smartphone. Modern tablets are built with wireless Internet or local area networks and a variety of software applications, including business applications, Web browsers and games. A tablet computer, commonly shortened to tablet, is a mobile device, typically with a mobile operating system and touchscreen display processing circuitry, and a rechargeable battery in a single, thin, and flat package. Tablets, being computers, do what other personal computers do, but lack some input/output abilities that others have. Modern tablets largely resemble modern smartphones, the only differences being that tablets are relatively larger than smartphones, with screens 7 inches or larger, measured diagonally, and may not support access to a cellular network. The touchscreen display is operated by gestures executed by finger or digital pen instead of the mouse, touchpad, and keyboard of larger computers. Portable computers can be classified according to the presence and appearance of physical keyboards. Two species of tablet, the slate and booklet, do not have physical keyboards and usually accept text and other input by use of a virtual keyboard shown on their touchscreen displays. To compensate for their lack of a physical keyboard, most tablets can connect to independent physical keyboards by Bluetooth or USB; 2-in-1 PCs have keyboards, distinct from tablets. E-reader devices An e-reader, also called an e-book reader or e-book device, is a mobile electronic device that is designed primarily for the purpose of reading digital e-books and periodicals. Any device that can display text on a screen may act as an e-reader; however, specialized e- reader devices may optimize portability, readability, and battery life for this purpose. Their main advantages over printed books are portability. This is because an e-reader can hold thousands of books while weighing less than one book and the convenience provided due to add-on features. NET Books 32 CU IDOL SELF LEARNING MATERIAL (SLM)

A netbook is a small mobile computing device that has less processing power and storage space than a laptop computer. Netbooks are extremely lightweight, and most do not include a CD/DVD drive. However, they do support a small keyboard for word processing and other inputs Netbooks were initially created as secondary computing options and targeted to the education market. However, they have become increasingly popular, particularly among students, bloggers and those how mainly use a laptop to access the Web. Netbooks are also ideal for cloud computing. MP4 players A handheld device that plays video in the MPEG-4 movie file format, Any media player software or BLU ray/DVD player that supports the MP4 movie file format. MPEG-4 Part 14 or MP4 is a digital multimedia container format most used to store video and audio, but it can also be used to store other data such as subtitles and still images. Like most modern container formats, it allows streaming over the Internet. The only filename extension for MPEG-4 Part 14 files as defined by the specification is .mp4. MPEG-4 Part 14 is a standard specified as a part of MPEG-4. Portable media players are sometimes advertised as \"MP4 Players\", although some are simply MP3 Players that also play AMV video or some other video format, and do not necessarily play the MPEG-4 Part 14 format. Internet TVs Internet TV is generally-available content distributed over the Internet. Internet TV is generally-available content distributed over the Internet. Unlike IPTV (Internet Protocol television), which is distributed over proprietary networks, Internet TV is available wherever a broadband connection exists. Internet TV, on the other hand, is available online and is more likely to be free. Internet TV options include Web-based shows, video on demand, streaming video and regular television shows hosted on the channel's websites. The two terms are often confused. Despite its name, however, IPTV is generally not available over the Internet. It's more like a replacement for cable TV with similar offerings and typically offered by the same carriers, for the same types of fees. Internet TV, on the other hand, is available online and is more likely to be free. Internet TV options include Web-based shows, video on demand, streaming video and regular television shows hosted on the channel's websites. Streaming television is the digital distribution of television content, such as TV shows, as streaming media delivered over the Internet. Streaming TV stands in contrast to dedicated terrestrial television delivered by over-the-air aerial systems, cable television, and/or satellite television systems. The use of streaming online video and streaming television is 33 CU IDOL SELF LEARNING MATERIAL (SLM)

concentrated on streaming video on demand platforms such as Netflix, Crackle, Amazon Prime Video, HBO Max, Peacock, Disney+, Apple TV+, BET+, and Paramount+. 2.2.5 The Android Market Google Play, formerly known as Android Market, is the official distribution storefront for Android applications and other digital media, such a music, movies and books, from Google. It is available on mobile devices and tablets that run the Android operating system supported Chrome OS devices and on the web. As such, in August 2008, Google announced Android Market, an online application store for Android devices, and made it available to users in October 2008. Using the Market application that is preinstalled on their Android device, users can simply download third- party applications directly onto their devices. Both paid and free applications are supported on the Android Market, though paid applications are available only to users in certain countries due to legal issues. Similarly, in some countries, users can buy paid applications from the Android Market, but developers cannot sell in that country. As an example, at the time of writing, users in India can buy apps from the Android Market, but developers in India cannot sell apps on the Android Market. The reverse may also be true; for example, users in South Korea cannot buy apps, but developers in South Korea can sell apps on the Android Market. Google also mentioned that it will continue to support “later versions of Android Market for as long as feasible.” Exactly what that means is anyone’s guess, but I think it’s safe to say that the company will eventually end support for Android Market on other versions of its operating system and probably sooner rather than later. Because Google has brought up the topic of its old app store recently, we decided to make a post explaining exactly what Android Market was, as well as when Google Play replaced it and why. Additionally, we’ll talk about how to upgrade to Google Play in case your device still has the old Android Market on board. Additionally, the company also rebranded Google Music to Google Play Music, Google Books to Google Play Books, and Google Movies to Google Play Movies, essentially bringing all the services under one name and making it clearer that you can access all of them from one place the Google Play Store. 2.2.6 The Android Developer Community With Android in its fourth version, there is a large developer community all over the world. It is now much easier to get solutions to problems, and find like-minded developers to share app ideas and exchange experiences. Here are some developer communities/sites that you can turn to for help if you run into problems while working with Android: 34 CU IDOL SELF LEARNING MATERIAL (SLM)

 Stack Overflow Stack Overflow is a collaboratively edited question and answer site for developers. If you have a question about Android, chances are someone at Stack Overflow is probably already discussing the same question and someone else had already provided the answer. Best of all, other developers can vote for the best answer so that you can know which are the answers that are trustworthy.  Google Android Training Google has launched the Android Training site that contains several useful classes grouped by topics. At the time of writing, the classes mostly contain useful code snippets that are very useful to Android developers once they have started with the basics. Once you have learned the basics in this book, I strongly suggest you look at the classes.  Android Discuss Android Discuss is a discussion group hosted by Google using the Google Groups service. Here, you will be able to discuss the various aspects of Android programming. This group is monitored closely by the Android team at Google, and so this is good place to clarify your doubts and learn new tips and tricks. 2.3 ANDROID ARCHITECTURE In order to understand how Android works, which shows the various layers that make up the Android operating system. The Android OS is roughly divided into five sections in four main layers:  Linux kernel-At the bottom of the layers is Linux - Linux 3.6 with approximately 115 patches. This provides a level of abstraction between the device hardware and it contains all the essential hardware drivers like camera, camera, keypad, keypad, display etc. Also, the kernel handles all the things that Linux is good at such as networking and a vast array of device drivers, which take the pain out of interfacing to peripheral hardware.  Android runtime - At the same layer as the libraries, the Android runtime 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, Dalvik is a specialized virtual machine designed specifically for Android and optimized for battery-powered mobile devices with limited memory and CPU.  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, you will find applications that ship with the Android device, as well as applications that you download and install from the Android Market. Any applications that you write are located at this layer 35 CU IDOL SELF LEARNING MATERIAL (SLM)

 Android operating pirating system is a stack of software components which is roughly divided into five sections and four main layers as shown below in the architecture diagram. Figure 2.1: Android architecture  Libraries - On top of Linux kernel there is a set of libraries including open-source Web browser engine WebKit, well known library, SQLITE database which is a useful repository for storage and sharing of application data, libraries to play and record audio and video, SSL libraries responsible for Internet security etc.  Android Libraries  This category encompasses those Java-based libraries that are specific to Android development. Development. Examples of libraries in this category include the application framework libraries in addition to those that facilitate user interface building, building, graphics drawing and database access. A summary of some key core Android libraries available to the Android developer is as follows  Android app − Provides access to the application model and is the cornerstone of all Android applications.  Android Content − Facilitates content access, access, publishing and messaging between applications and application components. 36 CU IDOL SELF LEARNING MATERIAL (SLM)

 Android Database − Used to access data published by content providers and includes SQ LITE database management classes.  Android opening− A Java interface to the OpenGL ES 3D graphics rendering API.  Android OS − Provides applications with access to standard operating system services including messages, system services and inter-process communication.  Android text − Used to render and manipulate text on a device display.  Android view − the fundamental building blocks of application user interfaces.  Android widget − A rich collection of pre-built user interface components such as buttons,  Labels, list views, layout managers, radio buttons etc.  Android webkit − A set of classes intended to allow web-browsing capabilities to be built into applications.  Having covered the Java-based core libraries barriers in the Android runtime, runtime, it is now time to turn our attention to  The C/C++ based libraries contained in this layer of the Android software stack. 2.4 SUMMARY  Whether you’re an experienced mobile engineer, a desktop or web developer, or a complete programming novice, Android represents an exciting new opportunity to write innovative applications for an increasingly wide range of devices.  Android is a mobile operating system that is based on a modified version of Linux. It was originally developed by a start-up of the same name, Android, Inc. In 2005, as part of its strategy to enter the mobile space, Google purchased Android and took over its development work.  Android is a mobile operating system based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. Android is developed by a consortium of developers known as the Open Handset Alliance and commercially sponsored by Google.  A smartphone is a cellular telephone with an integrated computer and other features not originally associated with telephones such as an operating system, web browsing, and the ability to run software applications.  A tablet is a wireless touch screen personal computer that is smaller than a notebook but larger than a smartphone. Modern tablets are built with wireless Internet or local 37 CU IDOL SELF LEARNING MATERIAL (SLM)

area networks and a variety of software applications, including business applications, Web browsers and games.  This category encompasses those Java-based libraries that are specific to Android development.  As technology has evolved, mobile phones have become about much more than simply making calls. With the introduction of tablets and Google TV, Android has expanded beyond its roots as a mobile phone operating system, providing a consistent platform for application development across an increasingly wide range of hardware. In Android, native and third-party applications are written with the same APIs and executed on the same run time. These APIs feature hardware access, video recording, location-based services, support for background services, map-based activities, relational databases, inter-application communication, Bluetooth, NFC, and 2D and 3D graphics. 2.5 KEYWORDS  Android made its official public debut in 2008 with Android 1.0 a release so ancient it didn't even have a cute codename. Things were pretty basic back then, but the software did include a suite of early Google apps like Gmail, Maps, Calendar, and YouTube, all of which were integrated into the operating system a stark contrast to the more easily updatable standalone-app model employed today.  Android architecture contains different number of components to support any android device needs. Android software contains an open-source Linux Kernel having collection of number of C/C++ libraries which are exposed through an application framework services.  Smartphone is a portable device that combines mobile telephone and computing functions into one unit. They are distinguished from feature phones by their stronger hardware capabilities and extensive mobile operating systems, which facilitate wider software, internet (including web browsing over mobile broadband), and multimedia functionality (including music, video, cameras, and gaming), alongside core phone functions such as voice calls and text messaging.  Developer community generally defined is a group of developers gathered in a place to achieve a common goal. This transitions your organization from having a support team answering technical questions or having a senior developer answering questions to a self-sufficient community that answers each other's questions.  Android library is structurally the same as an Android app module. It can include everything needed to build an app, including source code, resource files, and an Android manifest. However, instead of compiling into an APK that runs on a device, 38 CU IDOL SELF LEARNING MATERIAL (SLM)

an Android library compiles into an Android Archive file that you can use as a dependency for an Android app module. 2.6 LEARNING ACTIVITY 1. Search a latest android smartphone in Google, which contains all new latest features. ___________________________________________________________________________ __________________________________________________________________________ 2. Find the top 10 android smartphones in current year. ___________________________________________________________________________ __________________________________________________________________________ 2.7 UNIT END QUESTIONS A. DescriptiveQuestions 39 Short Questions 1. Write a short note on Android Architecture. 2. What Is Android? 3. Explain Smartphone. 4. Describe the E-reader devices. 5. What are Internet TVs? Long Questions 1. Explain the Android Versions. 2. Discuss the Features of Android. 3. Describe the Android Devices in the Market. 4. Describe the Android Developer Community. 5. Explain the Android Architecture. B. Multiple Choice Questions 1. What is Android? a. An operating system b. A web browser c. A web server d. None of these CU IDOL SELF LEARNING MATERIAL (SLM)

2. Under which of the following Android is licensed? a. OSS b. Sourceforge c. Apache/MIT d. None of these 3. For which of the following Android is mainly developed? a. Servers b. Desktops c. Laptops d. Mobile devices 4. Which of the following language android is based on? a. Java b. C++ c. C d. None of these 5. How many layers does is roughly divided into Android operating system is a stack of software components? a. 2 b. 3 c. 4 d. 5 Answers 1-a, 2- c, 3-d, 4- a, 5- c 2.8 REFERENCES Reference  Zigurd Mednieks, Laird Dornin, Blake Meike G, and Masumi Nakamura, 2011 “Programming Android”, O’Reilly books.  Android Programming: 2012, The Big Nerd Ranch Guide. 40 CU IDOL SELF LEARNING MATERIAL (SLM)

 Ian Lake and Reto Meier, 2018, Professional Android4th Edition. Textbooks  Joseph Annuzzi Jr., Lauren Darcey, and Shane Conder, 2014, Advanced Android Application Development.  Wei - Meng Le, 2012.Beginning Android 4 Application Development”, John Wiley & Sons, Inc.  Reto Meier, 2012, Professional Android 4 Application Development”, John Wiley & Sons, Inc. Websites  https://en.wikipedia.org/  https://www.gizbot.com/  https://www.geeksforgeeks.org/  https://www.tutorialspoint.com/ 41 CU IDOL SELF LEARNING MATERIAL (SLM)

UNIT 3: INTRODUCTION TO ANDROID PART 2 42 STRUCTURE 3.0 Learning Objectives 3.1 Introduction 3.2 Dalvik Virtual Machine 3.3 Android SDK 3.3.1 Installing the Android SDK Tools 3.3.2 Configuring the Android SDK Manager 3.3.3 Android SDK Features 3.4 .APK extension 3.4.1 What Is an APK File? 3.4.2 What Are APK Files Used For? 3.4.3 How Are APK Files Created? 3.4.4 Why Would I Install APK Files Manually? 3.5 Summary 3.6 Keywords 3.7 Learning Activity 3.8 Unit End Questions 3.9 References 3.0 LEARNING OBJECTIVES After studying this unit, you will be able to:  Explain Dalvik Virtual Machine.  Explain the Android SDK Features.  Understand Configuring the Android SDK Manager.  Explain how APK Files Are Created.  Describe Installing the Android SDK Tools.  Explain Why Would I Install APK Files Manually. CU IDOL SELF LEARNING MATERIAL (SLM)

3.1 INTRODUCTION Android sits alongside a new wave of modern mobile operating systems designed to support application development on increasingly powerful mobile hardware. Platforms like Microsoft’s Windows Phone and the Apple phone also provide a richer, simplified development environment for mobile applications; however, unlike Android, they’re built on proprietary operating systems. In some cases, they prioritize native applications over those created by third parties, restrict communication among applications and native phone data, and restrict or control the distribution of third-party applications to their platforms. Android offers new possibilities for mobile applications by offering an open development environment built on an open-source Linux kernel. Hardware access is available to all applications through a series of API libraries, and application interaction, while carefully controlled, is fully supported. In Android, all applications have equal standing. Third-party and native Android applications are written with the same APIs and are executed on the same run time. Users can remove and replace any native application with a third-party developer’s alternative; indeed, even the dialler and home screens can be replaced. When we talked about operating systems few years ago, the most common answers were Windows, Linux, and Mac operating system. However, with the undying competition in the mobile phones market, the next big thing entered was ANDROID, which in no time became the heart of smart phones. Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. Android is a mobile operating system developed by Google, based on a modified version of the Linux kernel and other open-sourcesoftware, and designed primarily for touch screen mobile devices such as smart phones and tablets. In addition, Google has further developed Android TV for televisions, Android Auto for cars and Wear OS for wrist watches, each with a specialized user interface. Variants of Android are also used on game consoles, digital cameras, PCs, and other electronics. The Android Operating System is a Linux-based OS developed by the Open Handset Alliance. The Android OS was originally created by Android, Inc., which was bought by Google in 2005. Google teamed up with other companies to form the Open Handset Alliance, which has become responsible for the continued development of the Android OS. The android is a powerful operating system, and it supports large number of applications in Smart phones. These applications are more comfortable and advanced for the users. The hardware that supports android software is based on ARM architecture platform. The android is an open-source operating system means that it’s free and any one can use it. The android has got millions of apps available that can help you managing your life one or other way and it is available low cost in market at that reasons android is very popular. Each time the OHA releases an Android version, it names the release after a dessert. Android 1.5 is known as Cupcake, 1.6 as Donut, 2.0/2.1 as Éclair, 2.2 as Froyo and 2.3 is dubbed Gingerbread. Once a version is released, so is its source code. The 43 CU IDOL SELF LEARNING MATERIAL (SLM)

Android OS is designed for phones. The important features of android are given below: It is open source. Anyone can customize the Android Platform. There are a lot of mobile applications that can be chosen by the consumer. It provides many interesting features like weather details, opening screen, live RSS feeds etc. It provides support for messaging services, web browser, storage, connectivity media, handset layout etc. Software developers who want to create applications for the Android OS can download the Android Software Development Kit for a specific version. The SDK includes a debugger, libraries, an emulator, some documentation, sample code and tutorials. For faster development, interested parties can use graphical integrated development environments such as Eclipse to write applications in Java. 3.2 DALVIK VIRTUAL MACHINE As we know the modern JVM is high performance and provides excellent memory The DVM is a virtual machine to run Android applications. The DVM executes Dalvik bytecode, which is compiled from programs written in the Java language. Note that the DVM is not a JVM. The Dalvik Virtual Machine is an android virtual machine optimized for mobile devices. It optimizes the virtual machine for memory, battery life, and performance. Dalvik is the name of a town in Iceland, The Dalvik VM was written by Dan Bornstein. The Dex compiler converts the class files into the DEX file that runs on the Dalvik VM. Multiple class files are converted into one DEX file. Programs for Android are commonly written in Java and compiled to bytecode for the Java virtual machine, which is then translated to Dalvik bytecode and stored in. DEXand. o DEX files; related terms DEX and de-o DEX are associated with respective bytecode conversions. The compact Dalvik Executable format is designed for systems that are constrained in terms of memory and processor speed. The successor of Dalvik is Android Runtime, which uses the same byte code and .DEX files, with the succession aiming at performance improvements transparent to the end users. The new runtime environment was included for the first time in Android 4.4 \"KitKat\" as a technology preview andreplaced Dalvik entirely in later versions; Android 5.0 \"Lollipop\" is the first version in which ART is the only included runtime. Let's see the compiling and packaging process from the source file: 44 CU IDOL SELF LEARNING MATERIAL (SLM)

Figure 3.1: Compiling and packaging process from the source file For Android, a new Virtual machine was developed by Google as stated above. It uses registers of the CPU to store the operands. So, no requirement of any pushing and popping of instructions, Hence making execution faster. The instructions operate on virtual registers, being those virtual registers memory positions in the host device. Register-based models are good at optimizing and running on low memory. They can store common sub-expression results which can be used again in the future. This is not possible in a Stack-based model at all. Dalvik Virtual Machine uses its own byte-code and runs “. DEX”file. Advantages  DVM supports the Android operating system only.  In DVM executable is APK.  Execution is faster.  From Android 2.2 SDK Dalvik has its own JIT compiler.  DVM has been designed so that a device can run multiple instances of the Virtual Machine effectively.  Applications are given their own instances. Disadvantages  DVM supports only Android Operating System.  For DVM very few Re-Tools are available.  Requires more instructions than register machines to implement the same high-level code.  App Installation takes more time due to DEX.  More internal storage is required. 45 CU IDOL SELF LEARNING MATERIAL (SLM)

Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready. 3.3 ANDROID SDK The first and most important piece of software you need to download is, of course, the Android SDK. The Android SDK contains a debugger, libraries, an emulator, documentation, sample code, and tutorials. Android SDK is a software development kit developed by Google for the Android platform. The Android SDK allows you to create Android apps, and you don't need to be an expert to use it. In this tutorial, I'll explain what the Android SDK is and how to get started with it. Android SDK comes bundled with Android Studio, Google's official integrated development environment for the Android operating system. You can learn about Android Studio and the Android App Development Kit in another of my articles. Android software development is the process by which applications are created for devices running the Android operating system. Google states that \"Android apps can be written using Java, and C++ languages\" using the Android software development kit, while using other languages is also possible. All non-JVM languages, such as Go, JavaScript, C, C++, or assembly, need the help of JVM language code, that may be supplied by tools, likely with restricted API support. Some programming languages and tools allow cross-platform app support. Third party tools, development environments, and language support have also continued to evolve and expand since the initial SDK was released in 2008. The official Android app distribution mechanism to end users is Google Play; it also allows staged gradual app release, as well as distribution of pre-release app versions to testers. The Android software development kit includes a comprehensive set of development tools. These include a debugger, libraries, a handset emulator based on QEMU, documentation, sample code, and tutorials. Currently supported development platforms include computers running Linux, Mac OS X 10.5.8 or later, and Windows 7 or later. As of March 2015, the SDK is not available on Android itself, but software development is possible by using specialized Android applications. 46 CU IDOL SELF LEARNING MATERIAL (SLM)

Figure 3.2: Android SDK The Android SDK is packaged in a zip fi le. You can download it and unzip its content into a folder, say C:\\Android 4.0\\. For Windows user, Google recommends that you download the installer_r15-windows.exe file instead and use it to set up the tools for you automatically. The following steps walk you through the installation process using this approach. 3.3.1 Installing the Android SDK Tools When you have downloaded the installer_r15-windows.exe fi le, double-click it to start the installation of the Android tools. In the welcome screen of the Setup Wizard, click next to continue. If your computer does not have Java installed, you will see the error dialog. However, even if you have Java installed, you may still see this error. If this is the case, click the Report error button and then click next. The Android software development kit includes different components, including SDK Tools, Build Tools, and Platform Tools. The SDK Tools primarily includes the stock Android emulator, hierarchy viewer, SDK manager, and ProGuard. The Build Tools primarily include AAPT, DX. Platform Tools include the Android debug shell. Installing for UBUNTU Linux If you are using UBUNTU 15.04 or 15.10, make sure to install the following packages. Otherwise, you may notice No such file or directory when running trying to execute the AAPT program that is part of the Android SDK toolset Run the following commands: Brew taps homebrew/cask Brew installs --cask android-SDK This will install the Android SDK tools in /usr/local/Cellar/android-SDK/<version number> 47 CU IDOL SELF LEARNING MATERIAL (SLM)

Installing the Android SDK (Automated Way) Gradle 2.2.0 now supports automatically downloading dependencies. Make sure to upgrade to the latest Gradle version. The Gradle plug in to manage dependencies is now deprecated. Installing the Android SDK (Manual Way) You will need to download the Android SDK without Android Studio bundled. Go to Android SDK and navigate to the SDK Tools Only section. Copy the URL for the download that's appropriate for your build machine OS. Figure 3.3: Installing the android SDK (Manual Way) Use WGET with the correct SDK URL: $ WGET https://dl.google.com/android/repository/tools_r25.2.3-macosx.zip Unzip and place the contents within your home directory. The directory names can be anything you like but save the files in somewhere easy to find. Run the SDK manager tool: $ Tools/bin/SDK manager –update.>$tools/bin/SDK manager \"platforms; android-25\" \"build-tools; 25.0.2\" \"extras;google;m2repository\" \"extras;android;m2repository\">$ tools/bin/SDK manager --licenses Directory structure on the build server Now it's time to set your build environment's PATH variable and other variables that will be use to locate Android. Edit your .bash profile file. If you're not using bash, edit the right CONFIG file for your environment.# Android >export ANDROID_SDK_ROOT=/Users/CIANDROID/android- SDK-ma COSX>export PATH=$PATH:$ANDROID_SDK_ROOT/tools >Save and quit. Reload .bash profile: > $ source ~/.bash_profile Installing via the GUI 48 CU IDOL SELF LEARNING MATERIAL (SLM)

At the prompt, type android and hit Enter to launch the Android SDK Manager in a window. If this doesn't work, your PATH variable has not been set up with the Android SDK location Figure 3.4: Installing via the GUI You will want to install the same Android SDK packages on your build machine as you did to get Grade running locally. Before you begin, look at the build gradefile in your project. Packages to install Here are the SDK package names you'll definitely wish to select:  Tools > Android SDK Tools  Tools > Android SDK Platform-tools  Tools > Android SDK Build-tools One version of the Android Platform, It should be the one you named in the android: compile SDK Version section of your build grade file. You will also want to download the extras: Android Support Repository Android Support Library 49 CU IDOL SELF LEARNING MATERIAL (SLM)

Note: Choose the Android SDK Build-tools for the version of Android that you listed in the build grade file as the android: build Tools Version target. If your build grade says Android build ToolsVersion '21'then make sure to download that API version in the Android SDK Manager.Installing via the Command Line You can also download the SDK packages using the command line with the --no-ui parameter. Android update SDK --no-UI –all, if you want to be selective about installing, you can use android list to view all the packages and apply the filter option for selective installs: SUDO android update SDK --no-ui --filters platform-tools. If you decide to be selective about which packages to be installed, make sure to include the extra Android Maven repository. Otherwise, you may not be able to use the latest support design library Android update SDK --no-UI --all --filter extra-android-m2repository.The Android SDK can be installed automatically using the latest version of Grade or downloading the Android SDK manually in several different ways. Below is an overview of all different approaches. Figure 3.5: Android support library 1 You will be asked to provide a destination folder to install the Android SDK tools. Enter a destination path and click next. When you are asked to choose a Start Menu folder to create the program’s shortcut, take the default “Android SDK Tools” and click Install, When the setup is done, check the “Start SDK Manager option and click Finish. This will start the SDK Manager 50 CU IDOL SELF LEARNING MATERIAL (SLM)