ucd android workshop

50
Android Workshop UCD, 10 th April 2010 #UCDDD

Upload: sean-murphy

Post on 17-May-2015

1.812 views

Category:

Documents


2 download

DESCRIPTION

This is a presentation I gave to a workshop I organized in UCD focused on Android.The talk is divided into two sections:- Android 101- My experience trying to put together a facebook/foursquare/android mobile app-- I did not progress very far in this endeavour

TRANSCRIPT

Page 1: UCD Android Workshop

Android WorkshopUCD, 10th April 2010

#UCDDD

Page 2: UCD Android Workshop

Objectives

Android 101 Overview of the platform Some market information

Development of Android based app Partial Walkthrough Two components:

Server side Facebook, foursquare

Mobile client Talks to server (or not!)

Page 3: UCD Android Workshop

ANDROID 101

Page 4: UCD Android Workshop

Overview

Background/history Android concepts Comments on APIs Comment on market

Page 5: UCD Android Workshop

Background/History

Android Inc developed vision for platform Acquired in 2005 by Google

Launched November 2007 In conjunction with Open Handset

Alliance Number of variants since

1.1, 1.5, 1.6, 2.0, 2.1 Google working with many handset

manufacturers and operators HTC, Sony Ericsson, Motorola, LG

Page 6: UCD Android Workshop

What is Android?

Mobile Operating system Linux kernel v2.6.x

Architecture for developing mobile applications Much work on developing concepts

Mobile OS differs from desktop OS

Large set of APIs Much functionality provided

Dalvik VM Native Interface available late 09

Page 7: UCD Android Workshop

Differences from THE OTHER ONE More open in general

Although key parts kept closed No constraints on store…

Except that they pay store is not available in Ire

Technical Multitasking

Until last Thurs Bluetooth Issues with multi-touch until recently

Page 8: UCD Android Workshop

Perspective of App Developer

Rich Java based framework Closer to Java SE than Java ME

Good separation of UI and functionality Rapidly evolving platform

Too fast in 09 Platform with rapidly growing user base

Rapidly increasing number of apps Do not have Apple toll bridge

Anything can be published

Page 9: UCD Android Workshop

What does Android app look like Set of Java classes

External jars need to be packaged Manifest describing application XML based descriptors of UI

Typically Packaged into apk file

For distribution in market and more generally

Can be signed

Page 10: UCD Android Workshop

Components

Application comprised of different components

Android defines 4 types of components Activities Services Broadcast receivers Content providers

Somehow notion of main not always necessary When writing a service, for example

Page 11: UCD Android Workshop

Activity

Idea is somehow single action user is engaged in Part of a task

Examples Choosing people from list of contact Entering some text Navigating around a map

Application can comprise of one or more activities Typically more

One activity initiates next activity

Page 12: UCD Android Workshop

Activity

Activities linked to views (somewhat) Android facilitates views which are

decoupled Defined in XML and bundled with

package Activity generally renders a specific

view View designed for specific activity

Page 13: UCD Android Workshop

Services

Like daemons Run for some period of time

providing service for activities Fetch network data or perform

calculation Music playback

Service runs in main thread Can initiate other threads if needed

Can bind to running service

Page 14: UCD Android Workshop

Broadcast receivers and Content Providers Broadcast receivers

Listen for broadcast messages Time change, language change

Do not have UI, but may engage with user Notification mechanism Can start activty

Content Provider Enables an application to share its own

data with another application

Page 15: UCD Android Workshop

Definition of the application – manifest.xml Every application has file defining components

Lists activities, services, etc Example:

<?xml version="1.0" encoding="utf-8"?> <manifest . . . > <application . . . > <activity

android:name="com.example.project.FreneticActivity"

android:icon="@drawable/small_pic.png" android:label="@string/freneticLabel" . . . > </activity> . . . </application> </manifest>

Page 16: UCD Android Workshop

Intents

More complex (subtle?) notion Application can be invoked with

different intents Eg from windows – file dragged onto app

Behaviour of application depends on intent ACTION_CALL, ACTION_MAIN,

ACTION_SYNC ACTION_MAIN most commonly used

Manifest indicates which activity initiated on ACTION_MAIN

Page 17: UCD Android Workshop

Tasks

Activities from multiple applications can be combined into tasks

Applications can be aware of activities extant in other applications Can invoke them with certain intent Typically such activities in a ‘suite’

A stack which retains user’s sequence of activities This is how user perceives application

Note: application now ambiguous/overloaded

Page 18: UCD Android Workshop

So what about processes?

Lots of flexibility Activities, components, receivers and providers

can be in single process Can be split quite arbitrarily over different

processes

Defined in manifest All process run as uid of application All components run in a single main thread

of application Blocking! Need to ensure longer term tasks run in new

thread

Page 19: UCD Android Workshop

Lifecycles - Activity

Three states for activity Active or running

Visible in foreground on screen Paused

Still visible, but not main focus When notification window open

Stopped Not visible, retaining state More likely to be terminated

Page 20: UCD Android Workshop

Activity Lifecycle – state changes Transitions

void onCreate(Bundle savedInstanceState)

void onStart() void onRestart() void onResume() void onPause() void onStop() void onDestroy()

Page 21: UCD Android Workshop

Processes and lifecycles

Android tends to use available resources Keeps things alive when in doubt

Processes have one of 5 states: Foreground, visible, service, background,

empty Process’s state may be linked to

another process Service tied to foreground process

When resources run low, lowest priority processes removed

Page 22: UCD Android Workshop

Android APIs

Mix of APIs from different sources Apache http libs, standard java se libs,

xml, json libs Android-specific APIs

Phone APIs Telephony, contacts, location, bluetooth/wifi

Interface APIs Gesture, speech Graphics

Widgets, webkit, opengl

Page 23: UCD Android Workshop

Android in the marketplace

Android activity intense right now Over 50 devices in production or

development Phones, tablets, e-readers, etc

Sales of 60k units per day Adds up to 22m per annum

iPhone sold 25m in 09

App store rocketing Apps doubled in Q110

Page 24: UCD Android Workshop

BUILDING AN ANDROID APP

Page 25: UCD Android Workshop

Building an Android App

Overview What the (intended) app looked like

Backend How this was realized

Mobile client How this was implemented

Page 26: UCD Android Workshop

BUILDING AN ANDROID APPOverview

Page 27: UCD Android Workshop

Planned app…

Integrate information from Facebook and Foursquare Facebook intended to provide rich

network of relationships Foursquare to provide location aspects

Idea Application targetted at group of people

on weekend away Hen/Stag party obvious example

Page 28: UCD Android Workshop

Intended workflow

On the web… User goes to (stand alone) website Selects friends going on weekend away

Facebook info Maps Facebook friends to Foursquare

friends Somehow (?)

Party going on tour stored in DB Both FB and FS uids stored

…and over to mobile…

Page 29: UCD Android Workshop

Intended workflow

Users download mobile app Used for duration of visit

App can be used to Check in

Check in on FS View group history Upload photos Make comments for group

Provide for richer group experience

Page 30: UCD Android Workshop

BUILDING AN ANDROID APPBackend

Page 31: UCD Android Workshop

Issues with development of backend Used Django framework

Rapid development Used facebook and foursquare

libraries for development Python/django libraries exist for both

Multiple python facebook libraries exist

Chose FB connect as main approach to talk to FB Django supports Oauth authentiation

based on this

Page 32: UCD Android Workshop

Issues with development of backend FB Connect libraries were a little limiting

Very premised on notion that friends (of interest) are only those subscribed to site Common way to use FB Connect

I wanted to extract all friends of given user Had to use some of the more

conventional FB capabilities More focused on apps in FB

Raised question of whether app should be housed in FB in first place

Page 33: UCD Android Workshop

Issues with development of backend Significant issue with mapping of FB

users to FS users Although my friends on FS do have FB

links (I don’t)

Can iterate through friends lists to find matches Email remainder to sign up for FS

Did not get this complete

Page 34: UCD Android Workshop

Issues with development of backend Foursquare API is still basic

Underestimated maturity of this as platform

Thought I could get friends history To show how people moved during the

weekend FS API only allows access to last

place friend was observed My backend needed to keep check ins

also To show fuller picture of weekend

Python FS API v simple to use

Page 35: UCD Android Workshop

Issues with development of backend Got basic capabilities working

Authentication via FB Select list of FB friends going on weekend Get FS id of those who have simple mapping

of FB to FS id In their FS profile

Did not get important parts working Mobile API Photo support Poor design decisions when constructing DB

Page 36: UCD Android Workshop

BUILDING AN ANDROID APPMobile client

Page 37: UCD Android Workshop

Android development

Short overview of tools Very important

Describe a little about how a simple Android app works

Issues I had with FB, FS integration

Page 38: UCD Android Workshop

Android – getting up and running Android SDK

Base tools common to all versions of platform Emulator framework cmd line tools to deploy apps on device

IDE – Eclipse preferred ADT plug in

Provides Android libraries, hooks into emulator, deployment, etc

Android Platform versions Install in SDK

Page 39: UCD Android Workshop

Basic tools

Main tool adb – flexible tool to enable host to talk to device

Used to install package on device Put file on device Shell into device Show device logs – these include application error traces

Other tools ddms – tool for connecting to on device process to

debug apkbuilder – tool to generate android package (apk)

Apk files used in market Can also be used to sign

Tools for db management, libraries, etc

Page 40: UCD Android Workshop

Eclipse plug-in

ADT is Eclipse plug-in for Android development Can be installed directly from online

resource Features include:

Knowledge of Android libraries Suggestions for completion of names/methods

Reasonable support for layout of views Drag and drop elements onto canvas

Good support for manipulation of manifest Debugging support

Page 41: UCD Android Workshop

External jars

Possible to add external jars to application Often v useful for talking to network services

Eg foursquare in this case

Issue with jar for shipping app Jar must be included in package

Unless it is known (how?) jar is available on device

Addition of external jars straightforward in Eclipse

Page 42: UCD Android Workshop

A basic activity

Class MyActivity extends Activity implements xxxListenersxxx { private EditText usernameText = null ; private EditText passwordText = null ; Private Button button = null ;

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); button = (Button)findViewById(R.id.Button01); button.setOnClickListener(this); }

public void onClick(View v) { …. }

}

Page 43: UCD Android Workshop

Basic activity: reacting to event

public void onClick(View v) { // do something when the button is clicked // put the values in username and password into

some // strings edittext1 =

(EditText)findViewById(R.id.EditText01); edittext2 =

(EditText)findViewById(R.id.EditText02); String username = edittext1.getText().toString(); String password = edittext2.getText().toString(); }

Page 44: UCD Android Workshop

Moving on to next activity

Approach is straightforward Create an intent and tell Android

Some code: Intent myIntent = new Intent(); myIntent.setClassName("com.android.samples", "com.android.samples.Animation1");

myIntent.putExtra("com.android.samples.SpecialValue", "Hello, Joe!"); // key/value pair, where key needs current package prefix.

StartActivity(myIntent);

Platform does manifest lookup to determine what to do

Page 45: UCD Android Workshop

When new activity instigated…

Can receive information from previous activity Transfer mechanism somewhat invisible Activity class has getIntent() method

Used to determine how activity was called

Some code: @Override public void onCreate(Bundle icicle) {

super.onCreate(icicle); Integer category =

this.getIntent().getIntExtra("category", -1);

Page 46: UCD Android Workshop

More generally…moving data around Simple data can be transferred

between activities using Bundles Android.app.Application can be

extended Incorporating global application state

Public/static fields/methods A bit clunky

Persistent storage: Application preferences, files, sqlite DB

Page 47: UCD Android Workshop

Issues with maps and keys

MapView API requires keys for use Keys linked to developer and to application

Unique key for each application

For development phase… Android generates certificate for signing

application automatically Not tied to certificate authority

Submit hash of this certificate to obtain working key

For release… Generate public/private key and use these to

create certificate

Page 48: UCD Android Workshop

Progress

Did not really get through facebook and foursquare functions on device

Foursquare api looks simple, easy to use on android Library exists for this

Facebook connect for android project is work in progress Did not look at this

Page 49: UCD Android Workshop

The 49th parallell

Some upcoming activities UCD/EPITA Android Hackathon

14-16 April Startup Weekend – NDRC

7-9 May Opportunities day

Invited Talk: ‘Mobile @ Google’ Dave Burke, Engineering Manager, Google

14 May

Page 50: UCD Android Workshop

Q&A