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

GDG Montreal

January 31, 2018
Tweet

More Decks by GDG Montreal

Other Decks in Technology

Transcript

  1. 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
  2. Demo What code to put where? What are the most

    used methods? onCreate() onStart() onResume() onPause() onStop() onDestroy() Visible
  3. Demo Do you see a bug in the current code?

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

    shell dumpsys activity activities
  5. 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
  6. How to pass data? Note: Do not inject Data in

    Activity / Fragment with setter Demo
  7. Handling rotations Data or UI state can be lost when

    doing a device rotation What do you do to solve it?
  8. What happens? • Usually, the Activity / Fragment state is

    saved (Example: App in Background) • An event modify his state (Examples: Network Response, Animation End)
  9. 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