Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Salt march 2011-getting started with android development

1,053 views

Published on

Salt march 2011-getting started with android development

Published in: Technology
  • Be the first to comment

Salt march 2011-getting started with android development

  1. 1. Getting Started with Android Development Rohit Ghatol
  2. 2. About Me Rohit Ghatol 1. Architect @QuickOffice 2. Project Mgr @Synerzip 3. Certified Scrum Master 4. Author “Beginning PhoneGap” @Apress 5. Founder TechNext Pune (Pune Developer Community) LinkedIn ProfileLinkedIn Profile
  3. 3. Topics • Understanding Android • Android Building Blocks • Putting Building Blocks Together • Latest things in Android World • Reference Material 3
  4. 4. Understanding Android 4
  5. 5. What is Android? • Software stack for mobile devices that includes • an operating system • middleware • key applications • SDK to develop application 5
  6. 6. Android Architecture 6
  7. 7. Android OS Names 7
  8. 8. 8 OS Version Nickname API Level Date 1.1 __ 2 9th February 2009 1.5 Cupcake 3 30 April 2009 1.6 Donut 4 5 September 2009 2.1 Eclair 7 26 October 2009 2.2 Froyo 8 20 May 2010 2.3 Gingerbread 9 6th December 2010 3.0 Honeycomb 11 22nd February 2011 4.X Icecream Sandwich 14 19th October 2011 http://en.wikipedia.org/wiki/Android_version_history
  9. 9. Key OS Capabilities 9
  10. 10. Android OS Capabilities • Phone and OS features – 3G/4G,GPS, Accelerometer, Compass, Camera, SQLite, Wifi, Bluetooth, etc – Near Field Communication – Cloud to Device Messaging (C2DM) – Direct Wifi
  11. 11. Android OS Capabilities • Notable Features of Android – All Applications are equal – Reuse of Data – Reuse of Functionality
  12. 12. All Applications are Equal • Replace Home Application • Replace Contacts, Dialer Applications • Replace SMS, Email Applications • Replace Settings Application • OEM Customizations (e.g HTC Sense) 12
  13. 13. Reuse of Data Default Contact Manager Replaces What happens to data feed into the default Contact Manager? New Contact Manager
  14. 14. Reuse of Data Default Contact Manager Replaces New Contact Manager Content Provider But Uses “Replaces” means by default the new app is launched, but old app still exists
  15. 15. Reuse of Functionality New Requirement Share with Friends using 1.SMS 2.Email Time to learn SMS API and Email API and code them into my application! More code! Hee hee  My CouponsMy Coupons
  16. 16. Reuse of Functionality SMS Mail Intention: Want to send Email Here are two applications who can do it for you? My CouponsMy Coupons
  17. 17. Reuse of Functionality SMS Mail My CouponsMy Coupons
  18. 18. Reuse of Functionality SMS Mail My CouponsMy Coupons
  19. 19. Android Environment Setup http://developer.android.com/sdk/in stalling.html 19
  20. 20. 20 Android SDKAndroid SDKEclipse ADT Android …..Android ….. ……………….………………. Android 3.2Android 3.2 Android 4.xAndroid 4.x Android 2.2Android 2.2 Google API 2.2Google API 2.2 SDK ManagerSDK Manager AVD ManagerAVD Manager Manages Emulator Emulator
  21. 21. Android Application Dex FileDex File Android Manifest Android Manifest ResourcesResources MyApp.apk Signed by Self Signed Private Key
  22. 22. Identity of Android Application 22 Identity Part Example Package Name com.sparklytix.android.app.twitter versionCode 1 (numeric value 2,3,4,..101,102) Private Key
  23. 23. Android Build Cycle 23 .java.java .apk.apk.dex.dex.class.class javac dx apt • AndroidManifest.xml • resources • AndroidManifest.xml • resources
  24. 24. How Applications behave? 24
  25. 25. 25 Linux KernelLinux Kernel Process Process Process Dalvik VM Dalvik VM Dalvik VM Uid 1Uid 1 Uid 2Uid 2 Uid 3Uid 3 data data com.xyz.email com.abc.skype com.koko.sukudo shared_prefs files databases . . . . . . . . . . . . UID 1 UID 2 UID 3
  26. 26. Android Building Blocks 26
  27. 27. Read more - http://developer.android.com/guide/topics/fundamentals.html ActivityActivity ServiceService Broadcast Receiver Broadcast Receiver Alarm Manager Noti- fication Manager Content Provider Content Provider IntentsIntents Content Resolver Building Blocks Other Components……
  28. 28. First Android Application 28
  29. 29. 29
  30. 30. 30
  31. 31. 31
  32. 32. 32
  33. 33. 33
  34. 34. 34
  35. 35. Interacting with Buttons 35
  36. 36. Interacting with Button 36
  37. 37. Interacting with Buttons 37
  38. 38. 38
  39. 39. Screen Navigation 39
  40. 40. 40
  41. 41. 41
  42. 42. 42
  43. 43. 43
  44. 44. 44
  45. 45. 45
  46. 46. startActivityForResult() 46
  47. 47. 47
  48. 48. 48
  49. 49. 49
  50. 50. 50
  51. 51. 51
  52. 52. Intents 52
  53. 53. Understanding Intent Need • Class Name Need • ACTION • CATEGORY • DATA
  54. 54. Program Launcher <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sample“ android:versionCode="1“ android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".HelloWorld" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion="4" /> </manifest> Program launcher shows all the activities which have MAIN Action and LAUNCHER category
  55. 55. Conflicts with implicit Intents So what happens two activities have the exact same intent filter and an intent is fired. Simple you choose one application, and you have an option to tell to system that application as the default application hence forth
  56. 56. Intent API Reference Intent to launch an Activity • Context.startActivity(intent) • Context.startActivityForResult(intent) Intent to launch an Service • Context.startService(intent) Intent to send a broadcast • Context.sendBroadCast(intent)
  57. 57. Activity 57
  58. 58. Activity Life Cycle
  59. 59. Foreground LifeCycleVisible LifeCycle Complete LifeCycle Activity Life Cycle (made easy) onCreate onDestroy onStart onStop onResume onPause
  60. 60. What to do in what method? onCreate onDestroy onStart onStop onResume onPause
  61. 61. Services 61
  62. 62. Calling Service ActivityActivity ServiceService void onStartCommand (Intent intent,…){ } startService(intent) Fire & ForgetFire & Forget
  63. 63. Calling Service ActivityActivity ServiceService 1. bindService(intent) 2. ….. 3. service.foo() 4. int result=service.bar() void foo(){ } int bar(){ } RPC StyleRPC Style
  64. 64. 64
  65. 65. Broadcast Receivers 65
  66. 66. Broadcast Receivers App 1App 1 Android OS App 2App 2 Your AppYour App Custom Event 1 Custom Event 1 Custom Event 2 Custom Event 2 Battery Low Battery Low RoamingRoaming BootBoot Network Change Network Change Interested in any of these Events.
  67. 67. Broadcast Receivers • No Life Cycle Methods • Only Call back method • 10 second limit before ANR • Need not register with Android Manifest • Can be registered at Runtime
  68. 68. Use case Email Application 68
  69. 69. Mail Application – Use Case
  70. 70. Building Blocks of Android Activity Service Broadcast Receiver Content Provider/ SQL ite Database Mail Sync Data Store (Email List) Data Store (Email List) Phone Boots Communication is using Intents
  71. 71. Activity Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Notifi. M.. Phone Boots
  72. 72. Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M..
  73. 73. Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M.. Broadcast R
  74. 74. Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M.. Broadcast R
  75. 75. Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M.. starts
  76. 76. Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M.. Completes
  77. 77. Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M.. Stores
  78. 78. Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M.. Stores Mail Notification
  79. 79. Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M.. Mail Notification
  80. 80. Mail Sync ServicePhone Boots Broadcast R Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M.. Mail Notification Data Store (Email List) Data Store (Email List) Database
  81. 81. Mail Sync ServicePhone Boots Broadcast R Data Store (Email List) Data Store (Email List) Database Events.. Alarm M.. Phone Boots Mail Sync (5 mins) Activity Notifi. M.. Mail Notification
  82. 82. Twitter App • All these Building blocks are covered in more detail on 3rd November at 3:40 p.m in “Building Twitter App for Android” 82
  83. 83. Q & A 83
  84. 84. More about Me • Twitter - http://twitter.com/#!/rohitghatol • TechGig - http://www.techgig.com/rohitghatol • LinkedIn - http://www.linkedin.com/in/rohitghatol • Presentations - www.slideshare.net/rohitsghatol/ • YouTube Tutorials - http://www.youtube.com/user/rohitssghatol

×