The document provides an introduction to Android, highlighting its open-source nature, customizable features, and extensive app ecosystem. It covers the Android platform architecture, including the Linux kernel, hardware abstraction layer, and application framework, as well as the development environment setup and APK file structure. Additionally, it explains core building blocks such as activities, services, content providers, and broadcast receivers, along with notification management in Android applications.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
19 views
fdc30f6c-7e5a-451c-a51d-05ff606cf11c-
The document provides an introduction to Android, highlighting its open-source nature, customizable features, and extensive app ecosystem. It covers the Android platform architecture, including the Linux kernel, hardware abstraction layer, and application framework, as well as the development environment setup and APK file structure. Additionally, it explains core building blocks such as activities, services, content providers, and broadcast receivers, along with notification management in Android applications.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 100
Introduction to Android
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Why Android? Open-source Customizable operating System
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Why Android? Reduce cost of development and overall complexity Larger community and developer reach Inter app integration Higher success ratio Rich development environment – variety of apps can be developed
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Android is an open-source operating system developed by Google, based on the Linux kernel. It is primarily designed for touchscreen devices like smartphones, tablets, smart TVs, wearable devices, and even cars.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ User Interface — The Android operating system provides a UI that is associated with the activity and presented to the user. ❏ Messaging — It supports messaging services (SMS, MMS).
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ Open Source — Android's source code is available under the Android Open Source Project (AOSP). Developers and device manufacturers can modify it to meet their needs.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ User-Friendly Interface — Android provides an intuitive and customizable interface, allowing manufacturers and users to personalize the look and feel.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ Web Browser — It is based on the open source WebKit layout engine, which is coupled with Chrome’s V8 JavaScript engine that supports HTML5 and CSS3. ❏ Connectivity — It has various connections such as Bluetooth, Wi-Fi, GSM/EDGE, CDMA, etc.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ Storage — A light relational database, SQL (SQLite), is used for storage purposes. ❏ Multi-touch — Android has native support for the multi-touch features.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ Multi-tasking — Android supports multitasking where the user can perform multiple tasks simultaneously. ❏ Multi-Language — It supports a single direction and bidirectional text features.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ Wi-Fi Direct —Android supports a feature that lets apps discover and pair directly over a high-bandwidth peer-to-peer connection. ❏ Android Beam —This feature is used to share instantly just by touching two NFC enabled phones together.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ Extensive App Ecosystem — Offers access to millions of applications on the Google Play Store, covering a wide range of categories.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ Diverse Hardware Support —Runs on devices with varied hardware configurations, from budget phones to high-end devices
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Features ❏ Frequent Updates — Regular updates with new features, performance improvements, and security patches.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Android API Levels https://apilevels.com/
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
to provide a smooth and secure operating system for mobile devices. It consists of several layers, each with a specific role.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Linux Kernel (Foundation Layer) It manages hardware components like the CPU, memory, and devices (e.g., cameras, sensors).
Provides core system
functionalities like security, power management, and process management.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Hardware Abstraction Layer (HAL) HAL acts as a bridge between the hardware and software. It allows Android software to communicate with device hardware without worrying about specific hardware details. For example, it lets the operating system control the camera, Wi-Fi, or Bluetooth through predefined interfaces.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Native Libraries These are written in C/C++ and handle tasks like graphics rendering (OpenGL), media playback, and database management (SQLite).
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Android Runtime (ART) ART is the engine that runs Android apps. It converts app code into machine code
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Application Framework (High-Level Layer) provides APIs (tools) that developers use to create apps. Includes features like: Activity Manager: Manages app lifecycle and navigation. Notification Manager: Handles notifications. Location Manager: Accesses GPS/location services. Content Providers: Share data between apps.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Applications (User Layer) This is what users see and interact with — the apps like WhatsApp, Instagram, or Google Maps.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
The Linux kernel manages hardware and resources. The HAL allows the system to communicate with hardware in a consistent way. The Native Libraries and Android Runtime handle heavy processing and run the apps. The Application Framework provides tools for developers to build user-friendly apps. Finally, users interact with the apps that sit on top of the entire stack.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Setting Up Development Environment • Install Java Development Kit (JDK) • Download Android Studio • It includes: • A code editor with IntelliSense and debugging tools. • An Android Emulator for testing. • Tools for building APK files. • Install Android SDK • provides tools, libraries, and APIs for app development. • Set Up an Emulator • Use the AVD (Android Virtual Device) Manager in Android Studio to create virtual devices (emulators) for testing apps on different Android versions and screen sizes.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Dalvik Virtual Machine (DVM) DVM is a Java-based virtual machine developed by Google. It is responsible for executing Android application code, which is written in Java and compiled into a format optimized for the mobile environment. Unlike the standard Java Virtual Machine (JVM), which runs Java bytecode, the Dan Bornstein DVM executes Dalvik Executable (DEX) bytecode.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Android apps are written in Java (or Kotlin) and compiled into Java bytecode (.class files) using the Java compiler. These .class files are then converted into a single .dex (Dalvik Executable) file using the Android tool dx. This process optimizes the code for the DVM to reduce memory consumption and improve runtime performance.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
With the release of Android 5.0 (Lollipop), ART replaced DVM. ART uses Ahead-of-Time (AOT) Compilation, where apps are compiled during installation, improving performance and reducing app launch time. ART also introduced better debugging and profiling tools, as well as improved garbage collection.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in .apk File Extension The .apk (Android Package) file is the format used to distribute and install applications on Android devices. An APK file is essentially a compressed archive (similar to a .zip file) containing all the components needed to run an app.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
An APK file consists of several key components: 1. DEX Files: Contains the compiled code of the app in Dalvik Executable (DEX) format. DEX files are executed by the DVM or ART. 2. AndroidManifest.xml: This file provides essential metadata about the app, including App components, Required permissions, Minimum and target API levels 3. Resources: UI elements, layouts, and graphics used in the app.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
4. META-INF Directory: Contains metadata about the APK, including the app's signature for verifying authenticity and the certificate used to sign the app. 5. LIB Directory: Contains compiled native code libraries for different CPU architectures 6. Assets Directory: Contains app-specific, raw asset files (e.g., fonts, custom datasets)
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in How is an APK File Created? When developers build an Android application in Android Studio: Source code is compiled into DEX bytecode. Resources are packaged. All components are bundled into an APK file using the Android build tools. The APK is then digitally signed with a certificate to ensure its integrity and authenticity.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
How Does an APK File Work? Users can download APK files from the Google Play Store or other sources. Android's Package Installer installs the APK, verifying its signature and unpacking its contents. When an app is launched: The DEX code is executed by the Dalvik Virtual Machine (or ART in modern devices). Resources are loaded as specified in the AndroidManifest.xml file.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Activity An activity is a class that represents a single screen. An application typically has multiple activities, and the user flips back and forth among them. Activity Manager is responsible for creating, destroying, and managing activities.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Starting state: When an activity doesn’t exist in memory, it is in a starting state. Running state: The activity in a running state is the one that is currently on the screen and interacting with the user. - such as typing, touching the screen, and clicking buttons
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Paused state: When an activity is not in focus (i.e., not interacting with the user) but still visible on the screen, we say it’s in a paused state. Stopped state: When an activity is not visible, but still in memory, we say it’s in a stopped state.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Destroyed state: A destroyed activity is no longer in memory. - Before the activity is destroyed, Activity Manager can perform certain actions, such as save any unsaved information.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Service Service is a background process that can run for a long time. For example, you might want your music player to play music even as you are flipping between other applications.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Content Provider Content Providers are used to share data between the applications. For example, • Contacts Provider is a content provider that exposes all user contact data to various applications. • Settings Provider exposes system settings to various applications, including the built-in Settings application. • Media Store is responsible for storing and sharing various media, such as photos and music, across various applications.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Broadcast Receivers Broadcast Receivers simply respond to broadcast messages from other applications or from the system. Example: Receiving SMS, battery level changes.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Detailed Example: Music Player App Activity: The main screen showing the list of songs. Service: A background service playing the music. BroadcastReceiver: Listens for headphone plug/unplug events to pause/resume music. Content Provider: Manages access to the music files stored on the device.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Notifications A notification is a message that Android displays outside your app's UI to provide the user with reminders, communication from other people, or other timely information from your app.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Beginning with Android 5.0, notifications can briefly appear in a floating window called a heads-up notification. The heads-up notification appears when your app issues the notification. It disappears after a moment, but it remains visible in the notification drawer as usual.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Beginning with Android 5.0, notifications can appear on the lock screen. Starting with Android 8.0, users can disable or enable lock screen notifications for each notification channel.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
In supported launchers on devices running Android 8.0 (API level 26) and higher, app icons indicate new notifications with a colored badge known as a notification dot on the corresponding app launcher icon.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Starting in Android 7.0 (API level 24), you can add an action to reply to messages or enter other text directly from the notification. Starting in Android 10 (API level 29), the platform can automatically generate action buttons with suggested intent-based actions.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Expandable notification
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
to deliver multiple notifications, grouping the separate notifications into a group, was made available on Android 7.0 and higher.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel or they don't appear. This lets users disable specific notification channels for your app instead of disabling all your notifications.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Starting in Android 5.0 (API level 21), users can enable Do Not Disturb mode, which silences sound and vibration for all notifications.
There are three levels available in Do Not Disturb mode:
Total silence: blocks all sounds and vibrations, including from alarms, music, videos, and games. Alarms only: blocks all sounds and vibrations, except from alarms. Priority only: users can configure which system-wide categories can interrupt them, such as only alarms, reminders, events, calls, or messages. For messages and calls, users can filter based on sender or caller.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Post limits Beginning with Android 8.1 (API level 27), apps can't make a notification sound more than once per second. If your app posts multiple notifications in one second, they all appear as expected, but only the first notification per second makes a sound.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
1. Small icon: required; set using setSmallIcon(). 2. App name: provided by the system. 3. Time stamp: provided by the system, but you can override it using setWhen() or hide it using setShowWhen(false). 4. Large icon: optional; usually used only for contact photos. Don't use it for your app icon. Set using setLargeIcon(). 5. Title: optional; set using setContentTitle(). 6. Text: optional; set using setContentText(). Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in View In Android, a View (public class Views) is the basic building block for creating UI components. Each View is a fundamental element for creating various types of interactive and display components in an app.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Basic Views include:
TextView: used to display text to the user.
EditText: interactive TextView that allows
users to input and edit text. It’s commonly used in forms, search bars, and messaging apps.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Button: When a user taps a button, it triggers an event in the app, allowing it to respond to the user’s input.
ImageView: used for displaying images.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
CheckBox: multiple options that can be either checked or unchecked
RadioButton: used for making a
single selection from a group of options.
Switch: is a two-state toggle that
can select between two options, often used in settings for turning a feature on or off.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
ProgressBar: is used to display the progress of an operation, providing visual feedback to the user.
SeekBar: is a type of ProgressBar that adds a
thumb to the progress line which a user can drag to set a value within a predefined range. It’s often used for settings like adjusting volume or screen brightness.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in View Group A View Group holds together other Views or even View Groups. A View Group doesn’t display any content of its own but serves as a container to organize and manage other Views.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Layouts Layouts serve as the cornerstone for designing and arranging user interfaces. They can often include several View Groups and are the map that dictates how different views and elements are organized on the screen.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Types of Layouts LinearLayout: organizes Views in a linear order, horizontally or vertically. This layout is particularly useful for creating forms, toolbars, or any interface where a sequential arrangement of elements is needed.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
GridView: displays items in a two-dimensional, scrollable grid. GridView is ideal for displaying a collection of images, icons, or data in a uniform grid, like a photo gallery or a settings menu.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
TableLayout: it arranges Views in a grid-like format. This layout is beneficial when creating calculators, timetables, or any interface with a tabular structure.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
FrameLayout: It’s a simple container used to display a single item, like an image or a piece of text.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
ListView: displays a list of scrollable items, automatically inserted into the list using an Adapter. It’s efficient for displaying datasets that scroll vertically, like a contact list or a menu.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
AbsoluteLayout: enables you to specify the exact location of child Views. Due to its lack of flexibility and the complexity of maintaining it across various screen sizes, it’s generally avoided in modern Android development.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
RelativeLayout: allows Views to be positioned in relation to each other or to the parent container.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Constraint Layout: used in Android view in which we set various constraints for various views with respect to screen or various views. app:layout_constraintLeft_toLeftOf:
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in In Android development, layouts as part of the general UI structure of your app are defined by XML files. XML layout files start with the <layout> tag followed by a root ViewGroup, such as <LinearLayout>, <RelativeLayout>, etc. Each View and ViewGroup in the layout has attributes. Ex: android:text="Hello World!";
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="16dp" android:padding="8dp" android:text="Hello, I am a TextView" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:paddingBottom="4dp" android:paddingEnd="8dp" android:paddingStart="8dp" android:paddingTop="4dp" android:text="Hello, I am a Button" /> </LinearLayout>
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
First Sample Android Application
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Drawable Resource A drawable resource is a general concept for a graphic that can be drawn to the screen & which you can retrieve with APIs such as getDrawable(int) or apply to additional XML resource with attributes such as android:drawable & android:icon.
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in
Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in Apoorva S., Asst. Prof., Dept of CS www.iadc.ac.in