Android Workshop (Night of Chances 2015)

  • Published on
    09-Aug-2015

  • View
    74

  • Download
    2

Transcript

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