Tuesday, March 5, 2024

Android java: behaviour state when configuration change (rotating mobile phone) Android N (7.0 / API 24)

After rotating mobilephone

  1. onConfigurationChanged
  2. onPause
  3. onSaveInstanceState
  4. onStop
  5. onDestroy

Following

  1. onStart
  2. onRestoreInstanceState
  3. onResume

NOTE: Important to keep state UI

  • Save any state in onSaveInstanceState
  • Restore InstanceState  in onRestoreInstanceState

To restore UI from InstanceState:

  • restore in onResume
  • if you use background service in OnStart, wait until it is finish. Easier way is UI handler -> handleMessage  

No comments:

Post a Comment