Basics of Android App Development

  • View
    195

  • Download
    4

Embed Size (px)

Text of Basics of Android App Development

  • Basics: Development of Android AppsArchitecture and Best practices

    Vishal Kumar Jaiswal

    IIEST Shibpur

    June 29, 2016

    Vishal Kumar Jaiswal (IIEST Shibpur) 1/ 29 June 29, 2016 1 / 29

  • Table of Contents

    1 Introduction

    2 Architecture

    3 Libraries

    4 Runtime

    5 Framework

    6 Components

    Vishal Kumar Jaiswal (IIEST Shibpur) 2/ 29 June 29, 2016 2 / 29

  • Introduction

    Overview

    Free and open source linux based operating system,Developed by Open Handset Alliance,Provides unified approach to application development,Provides SQLite relational database, webkit open source webbrowser,App development in JAVA programming language using AndroidSDK,Primary app store Google Play,Software required: JAVA JDK, Android SDK

    Vishal Kumar Jaiswal (IIEST Shibpur) 3/ 29 June 29, 2016 3 / 29

  • Architecture

    Vishal Kumar Jaiswal (IIEST Shibpur) 4/ 29 June 29, 2016 4 / 29

  • Architecture

    Architecture

    Linux Kernel:A level of abstraction between the device hardware.Contains all the essential hardware drivers like camera, keypad,display etc.Interfacing with hardware.

    Libraries:Provides JAVA - based set of libraries like libc, SQLite, SSL, Webkitweb browser engine and C/C++ libraries to facilitate interfacebuilding, graphics drawing, and database access.

    Vishal Kumar Jaiswal (IIEST Shibpur) 5/ 29 June 29, 2016 5 / 29

  • Libraries

    Android Library

    android.app:Provides access to application model, cornerstone for all apps.android.content:Facilitate content access, publishing, and messaging between,applications and application components,android.database:Used to access data from database also includes SQLite DBMSclasses,android.opengl:JAVA interface to the OpenGL 3D graphics rendering API,

    Vishal Kumar Jaiswal (IIEST Shibpur) 6/ 29 June 29, 2016 6 / 29

  • Libraries

    Android Library[Contd....]

    android.os:provides applications with access to standard operating systemservices like interprocess communication, system services,android.text:renders and manipulates text on a device display,android.view:building block of application user interface,android.widget:provides pre-built UI components viz. Buttons, labels, list views,radio buttons,android.webkit:allow web browsing to be built into applications.

    Vishal Kumar Jaiswal (IIEST Shibpur) 7/ 29 June 29, 2016 7 / 29

  • Runtime

    Android Runtime

    Provides Dalvik Virtual Machine which is a kind of JAVA virtualmachine specifically designed and optimized for Android.The Dalvik VM enables every Android applications to run its ownprocess, with its own instance of the Dalvik virtual machine.Write Android applications using JAVA programming language.

    Vishal Kumar Jaiswal (IIEST Shibpur) 8/ 29 June 29, 2016 8 / 29

  • Framework

    Application Framework

    Provides higher level services to applications in form of JAVA classes.Android developers are allowed to make use of these services in theirapplications.It includes:

    Activity Manager: Controls all aspects of the application lifecycle.Content Providers: Allows applications to publish and share datawith other applications.Resource Manager: Provides access to color settings, UI layouts.Notification Manager: Allows applications to display alerts andnotifications to the user.View System: Used to create application UI.

    Vishal Kumar Jaiswal (IIEST Shibpur) 9/ 29 June 29, 2016 9 / 29

  • Components

    Application components

    Loosely coupled by the application manifest file AndroidManifest.xmlthat describes each component of the application and their interactionwith each other.

    Activity,Service,Broadcast Receiver,Content Provider;

    Vishal Kumar Jaiswal (IIEST Shibpur) 10/ 29 June 29, 2016 10 / 29

  • Components

    Activity

    Vishal Kumar Jaiswal (IIEST Shibpur) 11/ 29 June 29, 2016 11 / 29

  • Components

    Activities

    Represents a single screen with a UI.For example, an email application might have one activity thatshows a list of emails, another activity to compose an email, and yetanother activity for reading emails.Similar to main function in C/C++,onCreate will be called first ofall by Android system on launch of application.The activity class defines following callbacks i.e. events.The paused activity does not receive any user input and can notexecute any code,

    Vishal Kumar Jaiswal (IIEST Shibpur) 12/ 29 June 29, 2016 12 / 29

  • Components

    Activity lifecycle

    Vishal Kumar Jaiswal (IIEST Shibpur) 13/ 29 June 29, 2016 13 / 29

  • Components

    Activities[Contd..]

    Every activity should be declared in AndroidManifest.xml file.The main activity should be listed with an intent-filter that includesthe MAIN action and LAUNCHER category. If any of this is notincluded, app icon will not appear in home screens list of apps.If an application has multiple activities, one activity should bemarked as the activity to be launched, when the application islaunched.

    Vishal Kumar Jaiswal (IIEST Shibpur) 14/ 29 June 29, 2016 14 / 29

  • Components

    Services

    Runs in the background to perform long running operations withoutneeding to interact with the user and it works even if application isdestroyed.For example, a service might play music in the background while theuser is in a different application or it might fetch data over thenetwork without blocking user interaction with an activity.Possible states: Started, Bound

    Vishal Kumar Jaiswal (IIEST Shibpur) 15/ 29 June 29, 2016 15 / 29

  • Components

    Lifecycle of Services

    Vishal Kumar Jaiswal (IIEST Shibpur) 16/ 29 June 29, 2016 16 / 29

  • Components

    Broadcast Receivers

    Responds to broadcast messages from other applications or from thesystem,Also known as events or intents,For example, Application can initiate broadcasts to let otherapplications know that some data has been downloaded to thedevice and available for use. So, Broadcast Receiver will interceptthis communication and takes appropriate action.Create broadcast receiver and register it.

    Vishal Kumar Jaiswal (IIEST Shibpur) 17/ 29 June 29, 2016 17 / 29

  • Components

    Content Providers

    Supplies data from one application to others on request.Data may be stored in the filesystem, the database or somewhereelse.

    Vishal Kumar Jaiswal (IIEST Shibpur) 18/ 29 June 29, 2016 18 / 29

  • Components

    Additional Components

    The following components are used in construction of previously listedentities, their logic, and wiring between them. These components are :

    Fragments: Represents a portion of user interface in an Activity,Views: UI elements that are drawn on-screen including buttons, listforms etc;Layouts: View hierarchies that control screen screen format andappearance of the views,Intents: Messages to any interested BroadcastReceiver on launch ofstartActivity to communicate with a broadcast service,Resources: External elements, such as drawable pictures, stringsetc;Manifest: Configuration file for the application.

    Vishal Kumar Jaiswal (IIEST Shibpur) 19/ 29 June 29, 2016 19 / 29

  • Components

    Anatomy of Android application

    src: Contains java source files of the project. By default, it containsMAinActivity.java file having an activity class that runs when yourapp is launched using the app icon.gen: Dont modify it. Contains .R files that references all resourcesfound in your project.bin: Contains .apk file built by the ADT during the build processand everything else needed to run an android application.res/drawable/hdpi: Directory for drawable objects that aredesigned for high density screens.res/layout: Files defining app user interface.res/value: directory for XML files containing references toresources e.g. strings, color definitions.

    Vishal Kumar Jaiswal (IIEST Shibpur) 20/ 29 June 29, 2016 20 / 29

  • Components

    Anatomy[Contd...]

    AndroidManifest.xml: Describes the fundamental characteristics ofapp and its all components.MainActivity.java: Actual application file that gets converted toDalvik executable file and runs your application.strings.xml is located in the res/values folder and it contains all thetext that application uses. For example, the names of buttons,labels go into this file. Responsible for textual content.gen/com.example.helloworld/R.java works like glue between theactivity Java files like MainActivity.java and the resources likestrings.xml. This file will be automatically generated and dontmodify it.The activity.xml is a layout file available in res/layout directory, thatspecifies UI of application.TextView is an Android content used to build the GUI.

    Vishal Kumar Jaiswal (IIEST Shibpur) 21/ 29 June 29, 2016 21 / 29

  • Components

    Manifest.xml

    Declare all components in this file. Works as interface betweenandroid OS and your application. If you dont declare an elementhere, it will not be considered by your application.icon - points to the application icon available underres/drawable-hdpi. The application uses the image namediclauncher.png located in the drawable folder.name - specifies fully qualified class name of the Activity subclass.label - specifies a string to use as the label of the activity.You can define multiple activities using activity tags.

    Vishal Kumar Jaiswal (IIEST Shibpur) 22/ 29 June 29, 2016 22 / 29

  • Components

    Manifest.xml [contd..]

    The action for the intent filter is named android.intent.action.MAINto indicate that this activity serves as the entry point for theapplication.The category for the intent-filter is namedandroid.intent.category.LAUNCHER to indicate that application canbe launched from the dev