Android screen orientation Lifecycle
We might have some confusion on the android screen orientation change lifecycle of an Android activity. Sometimes you might observe that your activity getting restarted, while the you rotate the device. Sometimes nothing happens. Below is the simple rule for android screen orientation change lifecycle.
1. If you already @Override the onConfigurationChanged() function in your java code( in your Android activity class) for handle Android Screen Orientation Change. Then your activity will never restart for any screen orientation changes. As i explained it in point-4 above.
2. If you do not @Override onConfigurationChanged() function as above, then your running activity will get restart every time for any screen orientation change happens in your device. That means your activity will destroy first by calling onDestroy() API and then onCreate()method will call again for your running activity to restart it.
3. To properly handle your activity’s restart state, you need to restores its previous state through the normal Activity lifecycle, in which Android OS calls onSaveInstanceState() method before it destroys your activity. So that you can save your data(variable values)and your application state. You can then restore the previous state during onCreate() or onRestoreInstanceState() method call of your activity.
No comments:
Post a Comment