Upgrade to Pro — share decks privately, control downloads, hide ads and more …

App Lifecycle and Common Problems by Alan Le Corre

App Lifecycle and Common Problems by Alan Le Corre

1b77dd441f657f5aefb3e21283b252e6?s=128

GDG Montreal

January 31, 2018
Tweet

Transcript

  1. App Lifecycle and common problems by Alan Le Corre @alanlecorre

    on Slack - GDG Android Montréal
  2. Activity lifecycle

  3. None
  4. Fragment Lifecycle

  5. How I picture it onCreate() onStart() onResume() onPause() onStop() onDestroy()

    Visible
  6. What happens when…? - we background the App - we

    close the device - we kill the app - we launch another Activity onCreate() onStart() onResume() onPause() onStop() onDestroy() Visible Demo
  7. Demo What code to put where? What are the most

    used methods? onCreate() onStart() onResume() onPause() onStop() onDestroy() Visible
  8. Subscribe / unsubscribe

  9. Demo Do you see a bug in the current code?

    onCreate() onStart() onResume() onPause() onStop() onDestroy() Visible
  10. Activity Back Stack • How to monitor your stack? adb

    shell dumpsys activity activities
  11. None
  12. Beware of killable methods Demo

  13. Beware of reused Activities onCreate() onStart() onResume() onPause() onStop() onDestroy()

    Visible Demo
  14. Advice: when entering onResume() do NOT put hypothesis on App

    states like: • We have data fetched by a previous Activity • The user is logged in (if applicable) • The Activity stack is as expected • … How to pass data to the Activity / Fragment? onCreate() onStart() onResume() onPause() onStop() onDestroy() Visible
  15. How to pass data? Note: Do not inject Data in

    Activity / Fragment with setter Demo
  16. Get result from an Activity Demo

  17. Brushing over Difficult problems

  18. Handling rotations Data or UI state can be lost when

    doing a device rotation What do you do to solve it?
  19. None
  20. None
  21. None
  22. The infamous onSaveInstanceState()

  23. None
  24. None
  25. None
  26. What happens? • Usually, the Activity / Fragment state is

    saved (Example: App in Background) • An event modify his state (Examples: Network Response, Animation End)
  27. Any quick solution?

  28. Sum up onCreate() onStart() onResume() onPause() onStop() onDestroy() Visibl •

    Use the Reference Doc https://developer.android.com • Check how you launch and finish your Activities • unsubscribe listeners if applicable • Pass data the right way
  29. Questions?