UCD Android Workshop


Published on

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

  • Be the first to comment

UCD Android Workshop

  1. 1. Android Workshop<br />UCD, 10th April 2010<br />#UCDDD<br />
  2. 2. Objectives<br />Android 101<br />Overview of the platform<br />Some market information<br />Development of Android based app<br />Partial Walkthrough<br />Two components:<br />Server side<br />Facebook, foursquare<br />Mobile client<br />Talks to server (or not!)<br />
  3. 3. Android 101<br />
  4. 4. Overview<br />Background/history<br />Android concepts<br />Comments on APIs<br />Comment on market<br />
  5. 5. Background/History<br />Android Inc developed vision for platform<br />Acquired in 2005 by Google<br />Launched November 2007<br />In conjunction with Open Handset Alliance<br />Number of variants since<br />1.1, 1.5, 1.6, 2.0, 2.1<br />Google working with many handset manufacturers and operators<br />HTC, Sony Ericsson, Motorola, LG<br />
  6. 6. What is Android?<br />Mobile Operating system<br />Linux kernel v2.6.x<br />Architecture for developing mobile applications<br />Much work on developing concepts<br />Mobile OS differs from desktop OS<br />Large set of APIs<br />Much functionality provided<br />Dalvik VM<br />Native Interface available late 09<br />
  7. 7. Differences from THE OTHER ONE<br />More open in general<br />Although key parts kept closed<br />No constraints on store…<br />Except that they pay store is not available in Ire<br />Technical<br />Multitasking<br />Until last Thurs<br />Bluetooth<br />Issues with multi-touch until recently<br />
  8. 8. Perspective of App Developer<br />Rich Java based framework<br />Closer to Java SE than Java ME<br />Good separation of UI and functionality<br />Rapidly evolving platform<br />Too fast in 09<br />Platform with rapidly growing user base<br />Rapidly increasing number of apps<br />Do not have Apple toll bridge<br />Anything can be published<br />
  9. 9. What does Android app look like<br />Set of Java classes<br />External jars need to be packaged<br />Manifest describing application<br />XML based descriptors of UI<br />Typically<br />Packaged into apk file<br />For distribution in market and more generally<br />Can be signed<br />
  10. 10. Components<br />Application comprised of different components<br />Android defines 4 types of components<br />Activities<br />Services<br />Broadcast receivers<br />Content providers<br />Somehow notion of main not always necessary<br />When writing a service, for example<br />
  11. 11. Activity<br />Idea is somehow single action user is engaged in<br />Part of a task<br />Examples<br />Choosing people from list of contact<br />Entering some text<br />Navigating around a map<br />Application can comprise of one or more activities<br />Typically more<br />One activity initiates next activity<br />
  12. 12. Activity<br />Activities linked to views (somewhat)<br />Android facilitates views which are decoupled<br />Defined in XML and bundled with package<br />Activity generally renders a specific view<br />View designed for specific activity<br />
  13. 13. Services<br />Like daemons<br />Run for some period of time providing service for activities<br />Fetch network data or perform calculation<br />Music playback<br />Service runs in main thread<br />Can initiate other threads if needed<br />Can bind to running service<br />
  14. 14. Broadcast receivers and Content Providers<br />Broadcast receivers<br />Listen for broadcast messages<br />Time change, language change<br />Do not have UI, but may engage with user<br />Notification mechanism<br />Can start activty<br />Content Provider<br />Enables an application to share its own data with another application<br />
  15. 15. Definition of the application – manifest.xml<br />Every application has file defining components<br />Lists activities, services, etc<br />Example:<br /><?xml version="1.0" encoding="utf-8"?><br /><manifest . . . ><br /> <application . . . ><br /> <activity android:name="com.example.project.FreneticActivity"<br />android:icon="@drawable/small_pic.png"<br />android:label="@string/freneticLabel" <br /> . . . ><br /> </activity><br /> . . .<br /> </application><br /></manifest><br />
  16. 16. Intents<br />More complex (subtle?) notion<br />Application can be invoked with different intents<br />Eg from windows – file dragged onto app<br />Behaviour of application depends on intent<br />ACTION_CALL, ACTION_MAIN, ACTION_SYNC<br />ACTION_MAIN most commonly used<br />Manifest indicates which activity initiated on ACTION_MAIN<br />
  17. 17. Tasks<br />Activities from multiple applications can be combined into tasks<br />Applications can be aware of activities extant in other applications<br />Can invoke them with certain intent<br />Typically such activities in a ‘suite’<br />A stack which retains user’s sequence of activities<br />This is how user perceives application<br />Note: application now ambiguous/overloaded<br />
  18. 18. So what about processes?<br />Lots of flexibility<br />Activities, components, receivers and providers can be in single process<br />Can be split quite arbitrarily over different processes<br />Defined in manifest<br />All process run as uid of application<br />All components run in a single main thread of application<br />Blocking!<br />Need to ensure longer term tasks run in new thread<br />
  19. 19. Lifecycles - Activity<br />Three states for activity<br />Active or running<br />Visible in foreground on screen<br />Paused<br />Still visible, but not main focus<br />When notification window open<br />Stopped<br />Not visible, retaining state<br />More likely to be terminated<br />
  20. 20. Activity Lifecycle – state changes<br />Transitions<br />void onCreate(Bundle savedInstanceState) <br />void onStart() <br />void onRestart() <br />void onResume() <br />void onPause() <br />void onStop() <br />void onDestroy()<br />
  21. 21. Processes and lifecycles<br />Android tends to use available resources<br />Keeps things alive when in doubt<br />Processes have one of 5 states:<br />Foreground, visible, service, background, empty<br />Process’s state may be linked to another process<br />Service tied to foreground process<br />When resources run low, lowest priority processes removed<br />
  22. 22. Android APIs<br />Mix of APIs from different sources<br />Apache http libs, standard java se libs, xml, jsonlibs<br />Android-specific APIs<br />Phone APIs<br />Telephony, contacts, location, bluetooth/wifi<br />Interface APIs<br />Gesture, speech<br />Graphics<br />Widgets, webkit, opengl<br />
  23. 23. Android in the marketplace<br />Android activity intense right now<br />Over 50 devices in production or development<br />Phones, tablets, e-readers, etc<br />Sales of 60k units per day<br />Adds up to 22m per annum<br />iPhone sold 25m in 09<br />App store rocketing<br />Apps doubled in Q110<br />
  24. 24. Building an Android App<br />
  25. 25. Building an Android App<br />Overview<br />What the (intended) app looked like<br />Backend<br />How this was realized<br />Mobile client<br />How this was implemented<br />
  26. 26. Building an Android App<br />Overview<br />
  27. 27. Planned app…<br />Integrate information from Facebook and Foursquare<br />Facebook intended to provide rich network of relationships<br />Foursquare to provide location aspects<br />Idea<br />Application targetted at group of people on weekend away<br />Hen/Stag party obvious example<br />
  28. 28. Intended workflow<br />On the web…<br />User goes to (stand alone) website<br />Selects friends going on weekend away<br />Facebook info<br />Maps Facebook friends to Foursquare friends<br />Somehow (?)<br />Party going on tour stored in DB<br />Both FB and FS uids stored<br />…and over to mobile…<br />
  29. 29. Intended workflow<br />Users download mobile app<br />Used for duration of visit<br />App can be used to<br />Check in<br />Check in on FS<br />View group history<br />Upload photos<br />Make comments for group<br />Provide for richer group experience <br />
  30. 30. Building an Android app<br />Backend<br />
  31. 31. Issues with development of backend<br />Used Django framework<br />Rapid development<br />Used facebook and foursquare libraries for development<br />Python/django libraries exist for both<br />Multiple python facebook libraries exist<br />Chose FB connect as main approach to talk to FB<br />Django supports Oauthauthentiation based on this<br />
  32. 32. Issues with development of backend<br />FB Connect libraries were a little limiting<br />Very premised on notion that friends (of interest) are only those subscribed to site<br />Common way to use FB Connect<br />I wanted to extract all friends of given user<br />Had to use some of the more conventional FB capabilities<br />More focused on apps in FB<br />Raised question of whether app should be housed in FB in first place<br />
  33. 33. Issues with development of backend<br />Significant issue with mapping of FB users to FS users<br />Although my friends on FS do have FB links<br />(I don’t)<br />Can iterate through friends lists to find matches<br />Email remainder to sign up for FS<br />Did not get this complete<br />
  34. 34. Issues with development of backend<br />Foursquare API is still basic<br />Underestimated maturity of this as platform<br />Thought I could get friends history<br />To show how people moved during the weekend<br />FS API only allows access to last place friend was observed<br />My backend needed to keep check ins also<br />To show fuller picture of weekend<br />Python FS API v simple to use<br />
  35. 35. Issues with development of backend<br />Got basic capabilities working<br />Authentication via FB<br />Select list of FB friends going on weekend<br />Get FS id of those who have simple mapping of FB to FS id<br />In their FS profile<br />Did not get important parts working<br />Mobile API<br />Photo support<br />Poor design decisions when constructing DB<br />
  36. 36. Building an Android App<br />Mobile client<br />
  37. 37. Android development<br />Short overview of tools<br />Very important<br />Describe a little about how a simple Android app works<br />Issues I had with FB, FS integration<br />
  38. 38. Android – getting up and running<br />Android SDK<br />Base tools common to all versions of platform<br />Emulator framework<br />cmd line tools to deploy apps on device<br />IDE – Eclipse preferred<br />ADT plug in<br />Provides Android libraries, hooks into emulator, deployment, etc<br />Android Platform versions<br />Install in SDK <br />
  39. 39. Basic tools<br />Main tool<br />adb – flexible tool to enable host to talk to device<br />Used to install package on device<br />Put file on device<br />Shell into device<br />Show device logs – these include application error traces<br />Other tools<br />ddms – tool for connecting to on device process to debug <br />apkbuilder – tool to generate android package (apk)<br />Apk files used in market<br />Can also be used to sign<br />Tools for db management, libraries, etc<br />
  40. 40. Eclipse plug-in<br />ADT is Eclipse plug-in for Android development<br />Can be installed directly from online resource<br />Features include:<br />Knowledge of Android libraries<br />Suggestions for completion of names/methods<br />Reasonable support for layout of views<br />Drag and drop elements onto canvas<br />Good support for manipulation of manifest<br />Debugging support<br />
  41. 41. External jars<br />Possible to add external jars to application<br />Often v useful for talking to network services<br />Eg foursquare in this case<br />Issue with jar for shipping app<br />Jar must be included in package<br />Unless it is known (how?) jar is available on device<br />Addition of external jars straightforward in Eclipse<br />
  42. 42. A basic activity<br />Class MyActivity extends Activity implements xxxListenersxxx {<br />private EditTextusernameText = null ;<br />private EditTextpasswordText = null ;<br />Private Button button = null ;<br /> @Override<br /> public void onCreate(Bundle savedInstanceState) {<br />super.onCreate(savedInstanceState);<br />setContentView(R.layout.main);<br /> button = (Button)findViewById(R.id.Button01);<br />button.setOnClickListener(this);<br /> }<br /> public void onClick(View v) {<br />….<br />}<br />}<br />
  43. 43. Basic activity: reacting to event<br /> public void onClick(View v) {<br /> // do something when the button is clicked<br /> // put the values in username and password into some<br /> // strings<br /> edittext1 = (EditText)findViewById(R.id.EditText01);<br /> edittext2 = (EditText)findViewById(R.id.EditText02);<br /> String username = edittext1.getText().toString();<br /> String password = edittext2.getText().toString();<br />}<br />
  44. 44. Moving on to next activity<br />Approach is straightforward<br />Create an intent and tell Android<br />Some code:<br />Intent myIntent = new Intent();<br />myIntent.setClassName("com.android.samples", "com.android.samples.Animation1");<br />myIntent.putExtra("com.android.samples.SpecialValue", "Hello, Joe!"); // key/value pair, where key needs current package prefix.<br />StartActivity(myIntent); <br />Platform does manifest lookup to determine what to do<br />
  45. 45. When new activity instigated…<br />Can receive information from previous activity<br />Transfer mechanism somewhat invisible<br />Activity class has getIntent() method<br />Used to determine how activity was called<br />Some code:<br />@Override <br />public void onCreate(Bundle icicle) { <br />super.onCreate(icicle); <br />Integer category = this.getIntent().getIntExtra("category", -1); <br />
  46. 46. More generally…moving data around<br />Simple data can be transferred between activities using Bundles<br />Android.app.Application can be extended<br />Incorporating global application state<br />Public/static fields/methods<br />A bit clunky<br />Persistent storage:<br />Application preferences, files, sqlite DB <br />
  47. 47. Issues with maps and keys<br />MapView API requires keys for use<br />Keys linked to developer and to application<br />Unique key for each application<br />For development phase…<br />Android generates certificate for signing application automatically<br />Not tied to certificate authority<br />Submit hash of this certificate to obtain working key<br />For release…<br />Generate public/private key and use these to create certificate<br />
  48. 48. Progress<br />Did not really get through facebook and foursquare functions on device<br />Foursquare api looks simple, easy to use on android<br />Library exists for this<br />Facebook connect for android project is work in progress<br />Did not look at this<br />
  49. 49. The 49thparallell<br />Some upcoming activities<br />UCD/EPITA Android Hackathon<br />14-16 April<br />Startup Weekend – NDRC<br />7-9 May<br />Opportunities day<br />Invited Talk: ‘Mobile @ Google’<br />Dave Burke, Engineering Manager, Google<br />14 May<br />
  50. 50. Q&A<br />