Android Development PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document provides an overview of Android development, focusing on core concepts like Android Studio, UI design, and components. It also includes information about Android's history and API levels. The document's structure emphasizes key aspects of Android app creation.
Full Transcript
Android Development Java for Android Applications Developement Table of contents 01 02 03 Introduction Android Studio IDE Android Components 04 05 06 UI Desig...
Android Development Java for Android Applications Developement Table of contents 01 02 03 Introduction Android Studio IDE Android Components 04 05 06 UI Design Deployment Practical Part What is Android Development It is about creating applications for mobile, specifically Android, devices to be used to assist or serve for a certain purpose 01 Introduction What is Android? It is an open source and Linux-based operating system for mobile devices such as smartphones and tablet computers It is involved in other marketplaces like TVs, and wearables. It was developed by the Open Handset Alliance, led by Google It supports multitasking, allowing users to run multiple apps simultaneously Why Android? Market Dominance Open Source The largest installed base of any Android is based on the Linux kernel mobile platform and growing fast and offers flexibility for developers. Open-source code encourages innovation and customizations. Global Reach Versatile Development Access to billions of users via Google Supports Java, Kotlin, and C++. Play Store. Cross-platform frameworks like Flutter Devices available at all price points Extensive libraries and APIs for make Android apps accessible integrating modern features (e.g., worldwide AI/ML) Seamless integration with Google services Categories of Android Applications Android History and API Level Version SDK/ API level Version code Codename Year Android 15 Level 35 VANILLA_ICE_CREAM Vanilla Ice Cream 2 2024 API Level is an integer value that uniquely Android 14 Level 34 UPSIDE_DOWN_CAKE Upside Down Cake 2 identifies the framework API revision offered Android 14 targetSdk will need to be 34+ for new apps and app updates by August 31, 2024. 2023 by a version of the Android platform. Android 13 Level 33 TIRAMISU Tiramisu 2 Android 13 targetSdk must be 33+ for new apps and app updates since August 31, 2023. The framework API consists of: Android 12 Level 32 Android 12L S_V2 2022 ○ A core set of packages and classes Android 12 Level 31 Android 12 S Snow Cone 2 2021 ○ A set of XML elements and attributes Android 11 Level 30 R Red Velvet Cake 2 2020 Android 10 Level 29 Q Quince Tart 2 2019 for declaring a manifest file Android 9 Level 28 P Pie 2018 ○ A set of XML elements and attributes Android 8 Level 27 Android 8.1 O_MR1 for declaring and accessing resources Android 8 Level 26 Android 8.0 O Oreo 2017 ○ A set of Intents Android 7 Level 25 Android 7.1 N_MR1 Android 7 Level 24 Android 7.0 N Nougat 2016 ○ A set of permissions that applications Android 6 Level 23 M Marshmallow can request, as well as permission Android 5 Level 22 Android 5.1 LOLLIPOP_MR1 2015 enforcements included in the system Android 5 Level 21 Android 5.0 LOLLIPOP, L Lollipop Jetpack/AndroidX libraries require a minSdk of 21 or Android higher5since April 2024. Jetpack Compose requires a minSdk of 21 or higher. Google Play services v23.30.99+ ( Android 4 Level 20 Android 4.4W 3 KITKAT_WATCH 2014 Each Android platform version supports Android 4 Level 19 Android 4.4 KITKAT KitKat exactly one API Level, although support is libraries Jetpack/AndroidX Android require 4 a minSdk of 19 or higher since October 2023. Google Play services v21.33.56+ (July 2021) drops suppo Android 4 Level 18 Android 4.3 JELLY_BEAN_MR2 2013 implicit for all earlier API Levels (down to API Android 4 Level 17 Android 4.2 JELLY_BEAN_MR1 Level 1) Android 4 Level 16 Android 4.1 JELLY_BEAN Jelly Bean The first commercial version, Android 1.0, was Android 4 Google Play services v14.8.39+ Google(December Play services 2018) v14.8.39+ drops Google support (December Play for services API 2018) levels v14.8.39+ drops below support (December 16. 2012 for AP Android 4 Level 15 Android 4.0.3 –ICE_CREAM_SANDWICH_MR1 4.0.4 released on September 23, 2008. Android 4 Level 14 Android 4.0.1 –ICE_CREAM_SANDWICH 4.0.2 Ice Cream Sandwich Android 4 Earlier Jetpack/AndroidX libraries Earlier Jetpack/AndroidX required a minSdklibraries Earlier of 14 or Jetpack/AndroidX required higher. a minSdk libraries of 14 orrequired higher. Android History and API Level (Cont’d) The following attributes are declared in an application's manifest inside element or build.gradle file: ○ android:minSdkVersion — Specifies the minimum API Level on which the application is able to run. The default value is "1". ○ android:targetSdkVersion — Specifies the API Level on which the application is designed to run. In some cases, this allows the application to use manifest elements or behaviors defined in the target API Level, rather than being restricted to using only those defined for the minimum API Level. ○ android:maxSdkVersion — Specifies the maximum API Level on which the application is able to run. A manifest file includes the nodes that define the application components, security settings, test classes, permissions, and requirements that make up the application. 02 Android Studio IDE Application Development Tools Development Tools Comparison Aspect Native Development (Java/Kotlin) Cross-Platform Development (Flutter/React Native) Platform Android-specific (Java/Kotlin for Android) Supports multiple platforms (Android, iOS, Web, Desktop) Performance Best performance, optimized for Android hardware Slightly lower performance than native, but close to native Development Speed Slower due to separate codebases for each platform Faster development with shared codebase across platforms User Interface Customizable UI, highly platform-specific Limited customization for platform-specific UI but improving Mature ecosystem, extensive libraries and tools for Ecosystem/Community Android Growing community, large ecosystem Learning Curve Steeper for beginners (especially Java) Easier for web developers (React Native uses JavaScript) Codebase Maintenance Separate codebases for Android and iOS Single codebase for all platforms Access to most APIs, but may require additional plugins for Platform-Specific APIs Direct access to platform APIs and hardware some App Size Typically smaller size for Android apps Larger app size due to inclusion of cross-platform libraries High-performance apps, apps requiring deep Apps that need to run on multiple platforms with a single Popular Use Cases integration with Android codebase Examples Instagram, Google Maps, WhatsApp Google Ads, Alibaba, Instagram (React Native) EXtensible Markup Language EXtensible Markup Language (XML) is a markup language used to store and transport data in a structured format. Allows the definition of custom tags. Tag-based syntax (similar to HTML). Human-readable format. Platform-independent (works across various platforms). Data is separated from presentation (focus on content, not design) Used in web services, APIs, configuration files, etc. Used to define UI layouts and configuration files in Android applications Android Studio IDE We will develop Android applications in the Java language using the Android Software Development Kit (SDK) in Android Studio Android Studio is the official Integrated Development Environment (IDE) for Google’s Android operating system, built on JetBrains’ IntelliJ IDEA software and designed specifically for Android development. Android Studio – File Structure AndroidManifest.xml Java File Layout Drawable File Defines essential information Contains the Java code Defines the UI structure Stores graphical about the app, such as its for the app’s logic and (views, widgets, etc.) in resources like images, components (activities, behavior. This includes XML format. It determines icons, or shapes that can services), permissions, and activities, services, and how the user interface is be used in the app's UI app configuration. other app components arranged Mipmap File colors.xml File strings.xml File build.gradle File Stores app launcher icons Defines the colors used Stores text strings used in Contains the build in different resolutions for throughout the app, allowing the app, allowing for configuration for the app various screen densities easy color management and easier localization and module, such as (hdpi, mdpi, etc.) reusability in UI components management of text dependencies, SDK versions, and other project settings Android Studio – File Structure AndroidManifest.xml manifests activites app build src/main drawable activity_main.xml java … layout res mipmap colors.xml Gradle scripts strings.xml values styles.xml build.gradle Code Examples 03 Android Components Android Components They are the necessary building blocks that an Android application consists of. Activity Service Content Provider Represents a single A component that runs Manages access to screen with a user in the background shared data between interface (UI). without a UI. apps. Controls the UI and user Handles long-running Allows different apps to interaction. tasks like downloading read and write to a Every app must have at files or playing music. shared database, files, or least one activity, Can run even if the app even other data sources. usually a MainActivity. is not in the foreground. Examples include contacts, media files, or app data. Android Components (Cont’d) Intent Fragment Used to facilitate communication Represents a portion of a UI or between different components behavior that can be reused (activities, services, or broadcast within an activity. receivers). A way to modularize the UI and Can be explicit (targeting a functionality of an activity. specific component) or implicit Can be added, removed, or (indicating the action to be replaced dynamically during performed, without specifying the runtime. component, e.g., open link in any available browser). App component in Android Studio For each app component that you create in your app, declare a corresponding XML element in the manifest file: ○ for each subclass of Activity ○ for each subclass of Service ○ for each subclass of BroadcastReceiver ○ for each subclass of ContentProvider 04 UI Design Layouts Each activity will have a layout (UI) and a code (logic for interacting with the activity; functionality) Layouts define the structure and arrangement of UI elements on the screen. Used to create a user-friendly interface by arranging widgets like TextViews, Buttons, and Images. Common Layout Types: ○ LinearLayout: Arranges UI elements in a single row or column ○ RelativeLayout: Positions elements relative to each other or the parent container Example: A Button positioned below a TextView ○ ConstraintLayout: A flexible layout for complex designs Example: Center-aligning a Button in the screen Attributes (Layout & View) Attributes define the properties of UI elements or layout components. The syntax for attributes Namespace: ○ android: : Specify attributes provided by the Android SDK ○ app: : Attributes specific to libraries (e.g., ConstraintLayout, Material Design) Example of attribute name: layout_width, text, background Example of attribute value: dimensions -> "match_parent", strings, or references -> "@string/app_name“ Syntax for a reference ○ android:id="@+id/textView1": Assigns a unique/new ID to the TextView. ○ android:text="@string/hello_world": Sets the text from the strings resource. ○ app:layout_constraintTop_toTopOf="parent": Sets a constraint using the app namespace. Size Units Different units are used in Android layouts for defining dimensions, margins, padding, and text sizes Unit Use Case Scales Density-independent Pixels Dimensions (width, height, Yes - based on the screen's (dp) margins) density Yes - Respects the user's font Scale-independent Pixels (sp) Text sizes size preferences Pixel (px) Exact pixel dimensions No Relative dimensions in Percent (%) Yes ConstraintLayout View Elements Each component in the screen is called a View ○ Button They represent visual components displayed on A clickable UI element for the screen performing actions Layout is like container or box to contain the Example: Submit, Cancel buttons views Common Attributes: android:text, Example: android:onClick ○ TextView ○ ImageView Displays text to the user Displays images or icons Example: Titles, labels, or Example: App logo or photos paragraphs Common Attributes: android:src, Common Attributes: android:text, android:scaleType android:textColor, android:textSize ○ CheckBox ○ EditText A box that can be checked or An input field where users can enter unchecked to select an option text Example: Agree to terms and Example: Username and password conditions fields Common Attributes: android:hint, android:inputType Intents Intents are messaging objects that allow communication between components Provide inter-component communication and enable users to perform actions Types of Intents: ○ Explicit Intent: Directly specifies the target component (e.g., opening another activity in the same app) Example: Navigate from one screen to another ○ Implicit Intent: Does not specify the target component. The system determines the appropriate app or component to handle the request Example: Sharing content or opening a URL Components of an Intent: ○ Action: Specifies the operation to perform (e.g., Intent.ACTION_VIEW). ○ Data: URI or other data to act upon (e.g., a phone number or URL). ○ Extras: Key-value pairs to pass additional information. ○ Category: Provides additional information about the action. ○ Flags: Define how an intent should behave (e.g., launching in a new task). Common Actions: ○ Call a number: Intent.ACTION_CALL. ○ Send email: Intent.ACTION_SEND. ○ Pick an item: Intent.ACTION_PICK (e.g., from the gallery). Activity Life Cycle 05 Deployment Deployment To test your app in a development environment Involves running the app directly on a device or emulator via tools like Android Studio Does not involve signing the app with a release key or preparing it for end-users Typically uses a debug build that includes debugging tools, logs, and no optimizations Examples: ○ Running your app on a connected physical Android device using USB. ○ Running your app on an Android Virtual Device (AVD) in the emulator App Release To distribute the app to end users through platforms like Google Play or other channels. Involves creating a release build: ○ Signed with a release key. ○ Optimized and stripped of debugging tools. ○ Often includes code obfuscation for security. Outputs: APK or AAB files ready for distribution. Examples: ○ Generating a signed APK using Android Studio's Build menu. ○ Uploading the APK/AAB to the Google Play Console for review and publishing. 06 Practical Part Last Words The XML file deals with the design, presentation, layouts, blueprint, etc (as a front-end) while the java deals with working of buttons, variables, storing, etc (as a back-end).