Things to know about onCreate() calls

At first, it might look that onCreate() is very straightforward--it gets called only once when an Activity gets created. However, the tricky bit is that an Activity can get destroyed and created not just when it is actually started (with startActivity()).

An Activity will also be destroyed and created in the following cases:

  • A device is rotated so that the orientation changes from landscape to portrait or vice versa
  • A system language changes
  • On Android 7.0, in multiple Activity or Application configurations, an Activity's space is resized
  • Hardware keyboard is popped out

In all of these cases, the currently running Activity will be destroyed and created with a new configuration as a completely new instance (the same in-memory object will not be reused). Obviously, the entire lifecycle will be executed when it happens; so, the onPause(), onStop(), onDestroy(), onCreate(), onStart(), and finally onResume() will be called. We will soon see how important that is when working with Observables in Android.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.59.219