Introduction to mobile programming with Androids.

2,082 views

Published on

Delivered in Kaunas Technical University as part of NFQ academy (http://www.nfq.lt/atviros-paskaitos/)

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,082
On SlideShare
0
From Embeds
0
Number of Embeds
75
Actions
Shares
0
Downloads
74
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Introduction to mobile programming with Androids.

  1. 1. Intro to programmingwith Androids@MaksimGolivkinAndroid dev @Uber
  2. 2. Plan •  Brave mobile world •  Daily life-cycle •  Different screens •  Hybrid applications
  3. 3. Why “mobile” development?
  4. 4. In developing world
  5. 5. And in the most posh economies.
  6. 6. Smartphones, tablets and more
  7. 7. Only an Internet device?
  8. 8. What smart devices are made of?
  9. 9. Memory Ports Positioning Radios SensorsBuild-­‐in   Audio   Cellular   Mobile     Audio  SD  card   USB   GPS   Wi-­‐Fi   Photo/video   HDMI   Wi-­‐Fi   Bluetooth   Light   A-­‐GPS   NFC   AcceleraBon   MagneBc   Gyroscope   Proximity   … Flash, Stylo, Second Screen
  10. 10. Dongle empowering 3 billion $ business
  11. 11. Why Android?
  12. 12. Android createsa sweet choice.
  13. 13. Open mobile computing platform
  14. 14. Android accounts for64% in smartphones40% in tablets   of device sales in 2012 Q3
  15. 15. GooGPS show-case
  16. 16. Two big butts •  App profitability 1/6 of iOS •  Fragmentation
  17. 17. Summary•  Dawn of connected devices era.•  HW knowledge creates opportunities.•  Android is leading it.
  18. 18. Android OS
  19. 19. Designed for fast switching between apps
  20. 20. Applications “talk” between each other
  21. 21. There is always a Back button
  22. 22. Programming Android
  23. 23. APIs •  SDK – Java applications •  NDK – mostly games •  Hybrid – everybody should
  24. 24. Tools •  Eclipse •  Eclipse ADT plugin •  Android SDK •  USB drivers
  25. 25. Learn Android•  d.android.com•  stackoverflow.com•  AppDemo sample application•  youtube for Google I/O•  Android OS source code•  grepcode.comBooks!
  26. 26. Script vs. Application
  27. 27. uber.com Init Process Display Output DiePHP script life-cycle
  28. 28. Init Interact State Process Display DieApplication life-cycle
  29. 29. Screen~= Activity
  30. 30. In Memory ForegroundLaunch Created ResumedInteractPress StoppedHome
  31. 31. In Memory Visible ForegroundLaunch Created Started ResumedInteract Open otherActivity Paused Stopped
  32. 32. In Memory Visible ForegroundRe-Launch Started Resumed Interact Press Home Paused Stopped
  33. 33. Activities Stack (briefly)
  34. 34. 1 stScreen1. Resumed
  35. 35. 2 ndScreen2. Resumed1. Stopped
  36. 36. 3 rdScreen3. Resumed2. Stopped1. Stopped
  37. 37. Closes an applicationDelegates responsibility
  38. 38. PressingBack3. Resumed2. Stopped1. Stopped
  39. 39. Destroyinglastactivity2. Resumed1. Stopped
  40. 40. PressingHome3. Resumed2. Stopped1. Stopped
  41. 41. Stopseverything3. Stopped2. Stopped1. Stopped
  42. 42. Returnedto theapp3. Resumed2. Stopped1. Stopped
  43. 43. RunningIn TheBackground? … not all of them
  44. 44. Maintaining state
  45. 45. Activity/app life-time •  Parameters + Saved Instance State •  Singleton Singleton is king. Mind the GC!
  46. 46. Persistence •  Shared Preferences •  Files •  Server •  SQLite Do you really need it?
  47. 47. Service
  48. 48. Use cases•  Long actions in between activities•  Notifications, when app is dead•  Intensive calculationsConsider simply using Threads. Twice!
  49. 49. Fragments
  50. 50. Fragments enable multi-pane layouts
  51. 51. Resources
  52. 52. Lifeof an image
  53. 53. Using resourcesResources r = getResources();Drawable d = r.getDrawable(R.drawable.ic_american_express);ImageView icon = (ImageView) findViewById(R.layout.card_logo);icon.setDrawable(d);
  54. 54. Drawable vs. View
  55. 55. Screen~= ActivityEverythingelse~= Views
  56. 56. Summary (Android OS)•  Android is popular but poor, yet•  Learn life-cycle by heart•  Assess feasibility of Persistence and Services. Twice.
  57. 57. Many screens
  58. 58. Differentresolutions 320x480 px 1280x720 px
  59. 59. Samephysical size42 dp
  60. 60. Screen density pixel _ width 2 + pixel _ height 2screen _ density = diagonal _ in _ inches
  61. 61. Many resolutions 320x426 legacy phones 240x320 legacy phones 320x533 legacy phones 320x576 320x480 phones 320x533 phones 320x568 320x480 new phones 360x640 400x640 640x1067 tweener tablets 640x1138 480x800 tweener tablets 480x854 600x1024 1024x768 tablets 1280x768 1280x800 ...  
  62. 62. Landscapeis yet anotherresolution
  63. 63. Patterns
  64. 64. Stretching
  65. 65. Adding margins
  66. 66. Multi-pane
  67. 67. Switch points
  68. 68. Switch points Home base 240dp 320dp 360dp 400dp 426dp 480dp 533dp 568dp 578dp 640dpsmall size portrait small size landscape normal size landscape normal size portrait large size portrait resized elements margins added switch point (another layout)
  69. 69. Expensive way Boom! Home base 240dp 320dp 360dp 400dp 426dp 480dp 533dp 568dp 578dp 640dpsmall size portrait small size landscape normal size landscape normal size portrait large size portrait resized elements margins added switch point (another layout)
  70. 70. Prepairing graphics
  71. 71. Density bucketsldpi (low) 100 ~ 140 dpmdpi (medium) 140 ~ 200 dphdpi (high) 200 ~ 280 dpxhdpi (extra high) 280 ~ 340 dp
  72. 72. 1 dp = ? pxldpi 0.75mdpi 1hdpi 1.5xhdpi 2
  73. 73. Nine-patch Resizable area Content area
  74. 74. Nine patch •  Buttons •  Backgrounds
  75. 75. Summary (Many screens)•  Needs investment, but little surprise.•  One layout for a start.•  Resolution ignorance is ugly, but not ineffective.
  76. 76. Hybrid apps
  77. 77. “Our biggest mistake was betting too much on HTML5”, - Mark Zuckerberg
  78. 78. HTML5 reality in 2012
  79. 79. Hybrid champion:LinkedIn Native HTML/CSS   Native
  80. 80. Hybrid architecture Native JavaScript API HTML/CSS/ JavaScript
  81. 81. Native side WebView webView = (WebView) findViewByid(R.id.webview); webView.addJavascriptInterface(obj, "Android"); final String html = AssetUtil.readAssetsFile( context, filename); webView.loadDataWithBaseURL( "file://", html, "text/html","utf-8", null);
  82. 82. JavaScript side function onClick() { Android. jsOnNextArticle(this.id); }
  83. 83. “API” gluepublic void showArticle(long id, String content) { webView.loadUrl("javascript: jsShowArticle(" + id + ", " + Uri.encode(content) + "");")}..public void jsOnNextArticle(long articleId) { …}
  84. 84. “API” gluepublic void showArticle(long id, String content) { webView.loadUrl("javascript: jsShowArticle(" + id + ", " + Uri.encode(content) + "");")}..public void jsOnNextArticle(long articleId) { …}
  85. 85. Summary (Hybrid apps)•  Content centered apps•  FAQ, User License, …•  1-1.5x more effort than native•  Pays of when targeting >= 3 platforms
  86. 86. Read ON-  The real problem with Android fragmentation-  Where does Android fragmentation hide?-  The technical adventure building a hybrid app.-  Fast track to Android design. Interested in Android? @MaksimGolivkin Care to give feedback? maksim@golivkin.eu

×