Post on 17-May-2015
description
Android WorkshopUCD, 10th April 2010
#UCDDD
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!)
ANDROID 101
Overview
Background/history Android concepts Comments on APIs Comment on market
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
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
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
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
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
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
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
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
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
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
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>
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
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
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
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
Activity Lifecycle – state changes Transitions
void onCreate(Bundle savedInstanceState)
void onStart() void onRestart() void onResume() void onPause() void onStop() void onDestroy()
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
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
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
BUILDING AN ANDROID APP
Building an Android App
Overview What the (intended) app looked like
Backend How this was realized
Mobile client How this was implemented
BUILDING AN ANDROID APPOverview
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
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…
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
BUILDING AN ANDROID APPBackend
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
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
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
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
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
BUILDING AN ANDROID APPMobile client
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
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
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
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
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
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) { …. }
}
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(); }
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
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);
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
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
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
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
Q&A