Top Banner
Presented by On Ramp Android Do Androids dream of electric sheep? Understanding the Android platform A developers perspective
45

Introduction to Android Development

May 14, 2015

Download

Technology

Jumping Bean

"Understanding Android" - On Ramp's presentation at the GDG BarCamp Addis Ababa 27th April 2013. An introduction to Android application development.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to Android Development

Presented by On Ramp

Android

Do Androids dream of electric sheep?

Understanding the Android platformA developers perspective

Page 2: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

ObjectiveProvide a high level conceptual model for understanding how to

build Android Applications

Page 3: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

About Me

● South African open source solutions integrator,– Java developer,

– Drupal developer,

– Loves Linux,

● On Ramp– Ethiopian Company

● Linux, Java, Android training and development house● Specialising in mobile telecoms space

Page 4: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Agenda● Android Architecture● Supported Languages● Dalvik VM● Development Environments● Components – Building Blocks ● High Level Overview

Page 5: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Agenda● Important concepts

– Intents

– Activities, Services, Content Providers & Broadcast Receivers

– Resources

Page 6: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

What is Android?

Android is a software stack for mobile devices that includes an

operating system, middleware and key applications

Page 7: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Architecture

Page 8: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Architecture

● Linux Layer– Based on Linux,

– Source now part of mainline Linux V3.3

– Linux security, process management & networking

Page 9: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Architecture

● Linux Layer– Each app has its own Linux user,

– All files and resources owned by app user,

– Other processes, app cannot access other app's files/resources

Page 10: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Architecture

● Core libraries written in C/C++– Android runtime – Dalvik– Services exposed via application

layer,

– Reuses open source components – SQLite, FreeType etc

Page 11: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Architecture

● Framework layer – What your application interacts

with,

– API calls to framework services,

– Key concepts to grok Android API

Page 12: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Architecture

YOU!

● Application written to use services of the Android platform

Page 13: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Supported

Languages● Android applications can be

written in – Java

● Supports a subset of Java API,● Can use most Java libraries,

– C/C++ using native development kit

● Should only be when performance is an issue.

Page 14: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Supported Languages

– C/C++ using native development kit● Used to write components called from

Java

Page 15: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Supported Languages

● Second Class Citizens– Scripting languages via Scripting

Layer for Android– Javascript, Ruby, Python,LUA, Perl

– HTML 5 Apps● Important – Phonegap etc

Page 16: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Dalvik● Dalvik is a process

virtual machine– Application written in

Java

– Complied to Java byte code (.class files)

– Converted into Dalvik compatible files (.dex) when packaged

Page 17: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Dalvik● Why Dalvik?

– More compact & memory efficient than .class files

– Each application runs in its own process,

– Each process gets it own VM

– Packaging (apk) files are zipped .dex files

Page 18: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Development Environments

● Android SDK,– Debugger

● (ADB – Andorid Debugger Bridge)

– Libraries

– Emulator

● Supported IDE – Eclipse– ADT plugin

Page 19: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Development Environments

● Other IDE support– NetBeans

– IntelliJ

– Command line/text editor

● Build tool – Ant (official)

Page 20: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Development Environments

● Build tool – Maven (support from

springsource)

● Android applications have a directory structure– Naming of directories is

important especially for resources

Page 21: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Core Components

● Activities– UI Layer– Similar to UI controller for web apps

● Services– Provides services to other applications, no ui, run in

background

● Content Providers– Used to pass information between applications

● Broadcast receivers– Listen to system events and broad cast and react

Page 22: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Core Components

● Notifications– System notifications

Page 23: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

High Level Overview

● Different from web or desktop applications,

● Android in control of/manages application,– Constrained environment,

– Memory management,

– Power usage etc

Page 24: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

High Level Overview

● Components interact with one another indirectly.

● Android controls creation, life cycle of components

Page 25: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

High Level Understanding

● Applications can use components from other apps,

● Task Stack -– Android places UI components

(Activities), maybe from different apps, onto a task stack, as user navigates through an application

Page 26: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

High Level Overview

● Component life cycle controlled by platform,

● Platform provides life cycle methods to allow components to react to changes in life cycle– onStart

– onResume

– onPause etc

Page 27: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

High Level Overview

● Activity 2 & Activity 3 may be from different applications

Task Stack

Page 28: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

High Level Overview

● How does your activity request new component from Android?– API calls

– Via Intents ● Define what you would like to have

happen next,● Pass data to next activity● Receive data back

Page 29: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Intents● Intents

– can be specific -i.e require specific class or

– Ask for any activity that provides required service

● e.g view web page

Page 30: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Intents● Intent made up of

– Action: view web page,place call

– Category: what attribute the component must have for your action e.g must display home screen

– Extra: data to pass between components

Page 31: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Components Data Sharing

● How do components pass data between each other?– Bundles/Extra = can add data that

needs to be transferred with Intent

Page 32: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Summary

UI components belong to a task

Platform creates components on you behalf

API used to request component creation

Components have a life cycle

Components are building blocks for your app

Other apps may use your components

Page 33: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Android

Where to start?

Start coding Activity components

Page 34: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Activities● Main entry point for application,

● Configures user interface and handles events,

● Each activity has one window in which to draw,

Page 35: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Activities● UI layout is best done with xml

resource files,● Java code for handling events &

setting up UI● UI widgets extend View class

– Views are the display classes used by an activity

Page 36: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Activity UI Layout

● ADT plugin provides designer

● Similar to XHTM:

Page 37: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Activity Lifecycle

Page 38: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Activities Screen Flow

● Flow between activities or screens is not direct,

● Application framework handles this for you

● You ask framework to create next screen you wish to display

Page 39: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Activities

Screen Flow ● API Calls -

– startActivity(Intent)

– startActivityForResult(Intent)

Page 40: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Resources

● Resources are static content● Resources are managed by

generated code● Layout definitions● Images● String constants● Resource ids

Page 41: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Resources

● Resources are defined in ● xml files,● Images in folders

– Resources directory = res

– Naming of directories is important

Page 42: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Application Configuration

● Applications are groupings of components– Activities,

– Services

– Broadcast receivers

– Content provider

Page 43: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Application Configuration

● Apps are defined via manifest.xml– <application> defines

● launcher activity for app,● what intents your components are created to

handle

– <uses-permission> to identify what services your application requires access to

Page 44: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Security● Linux layer

– process level security,

– File level security

● Application layer– Request permission from user to

access services– manifest.xml <use-permission>

Page 45: Introduction to Android Development

1 May 2013 Presented by On Ramp Presented by On Ramp

Contact Info

● On Ramp Web Site – http://www.onramp.mobi

● Social Networks -– Twitter @mxc4– G+ MClarke4

● Email: – [email protected][email protected]