Android Workshop (Night of Chances 2015)

  • View
    74

  • Download
    2

Embed Size (px)

Transcript

  1. 1. Android Workshop tefan Mitrk
  2. 2. Why Android? 1 000 000 000 active users +
  3. 3. Workshop overview Basic theory Very short Quite a candy App description Simple architecture Coding
  4. 4. Activity
  5. 5. Activity Usually single screen Custom lifecycle
  6. 6. 3. onStop() Activity 1. onCreate() 4. onDestroy() 2. onStart() ...
  7. 7. Activity Screen orientation change
  8. 8. Activity Activity A 1 2 3
  9. 9. Activity Activity A 1 2 3
  10. 10. Activity Activity A Activity B 1 2 3 2
  11. 11. Activity Activity A Activity B 1 2 3 2 Intent
  12. 12. Intent
  13. 13. Intent Activity A Activity B 1 2 3 2 Intent Activity B Item 2
  14. 14. Intent start external app
  15. 15. Intent - start external app Activity A 1 2 3 Intent open website eset.com
  16. 16. Apps lifecycle
  17. 17. Apps lifecycle
  18. 18. Apps lifecycle
  19. 19. Apps lifecycle Memory (RAM)
  20. 20. Apps lifecycle Memory (RAM) onCreate()
  21. 21. Apps lifecycle Memory (RAM)
  22. 22. Memory (RAM) onStop()
  23. 23. Memory (RAM)
  24. 24. Apps lifecycle Memory (RAM) onCreate()
  25. 25. Apps lifecycle Memory (RAM)
  26. 26. Memory (RAM) onStop()
  27. 27. Apps lifecycle Memory (RAM)
  28. 28. Apps lifecycle Memory (RAM) Low memory
  29. 29. Apps lifecycle Memory (RAM) Low memoryonDestroy()
  30. 30. Apps lifecycle Memory (RAM)
  31. 31. Apps lifecycle Memory (RAM) onCreate()
  32. 32. How to work in background? For example music player
  33. 33. Service Long running operations Custom lifecycle No UI
  34. 34. Activity A Playlists Service Playing music Service Activity B Player controls
  35. 35. Activity A Playlists Service Playing music Service Activity B Player controls
  36. 36. Activity A Playlists Service Playing music Service Activity B Player controls play pause
  37. 37. Apps lifecycle Memory (RAM) Low memory App with service
  38. 38. Apps lifecycle Memory (RAM) Low memoryonDestroy() App with service
  39. 39. Broadcasts
  40. 40. Broadcasts
  41. 41. Broadcasts Broadcast receivers
  42. 42. Broadcasts Broadcast receivers Incomming message
  43. 43. Broadcasts Broadcast receivers Incomming message
  44. 44. Activity usually single screen Service background, long running Intent communication (inner/inter) Broadcast data/events propagation Theory summary
  45. 45. Problem to solve
  46. 46. Measure phone usage
  47. 47. Inspiration
  48. 48. Display Statistics
  49. 49. Display Statistics
  50. 50. Architecture Single Activity App UML 5.5 notation
  51. 51. Architecture Single Activity App
  52. 52. Architecture Broadcast receiver (display on/off) Single Activity App
  53. 53. Architecture Broadcast receiver (display on/off) screen turned on Single Activity App
  54. 54. ArchitectureBroadcast receiver (display on/off) screen turned on Service Single Activity App
  55. 55. Lets code!
  56. 56. Step 1 MainActivity.java WakeUps Application AndroidManifest.xml Declarations Permissions
  57. 57. Step 2 MainActivity WakeUps Application ServiceDisplayStatsService ScreenBroadcastReceiver
  58. 58. Step 2 MainActivity WakeUps Application ServiceDisplayStatsService ScreenBroadcastReceiver 1 Start Service
  59. 59. Step 2 MainActivity WakeUps Application ServiceDisplayStatsService ScreenBroadcastReceiver 1 Start Service 2 Listen to OFF broadcasts
  60. 60. Step 2 MainActivity WakeUps Application ServiceDisplayStatsService ScreenBroadcastReceiver 1 Start Service 2 Listen to OFF broadcasts 3 Display Hello Kitty message when screen turns on 4
  61. 61. Step 3 MainActivity WakeUps Application ServiceDisplayStatsService ScreenBroadcastReceiver ON/OFF 5 Pass info to service
  62. 62. Step 4 MainActivity WakeUps Application ServiceDisplayStatsService ScreenBroadcastReceiver ON/OFF 6 Calculate last wake up duration Persistence Helper
  63. 63. Step 5 MainActivity WakeUps Application ServiceDisplayStatsService ScreenBroadcastReceiver ON/OFF Display total wake ups number Persistence Helper 7
  64. 64. Thank you!