When the orientation is changed, the onDistroy method is called, which indicates that the activity is closed, and again a new activity is created with a new height and width.
when the orientation is changed, all objects of the Activity class will be destroyed, and when the Activity is restarted, they will be created again, if there is a large amount of data, it will take more time to reload all the data .. therefore, he prefers to separate and save all the data in the Non-Activity class and use in the Activity class by creating objects in the NonActivity class.
when the orientation change to the SaveInstanceState method and
using onSaveInstanceState, data will set or save some values ββwhen activity destroys and recreates
protected void onSaveInstanceState(Bundle icicle) { super.onSaveInstanceState(icicle); icicle.putLong("param", value); }
when the activity restarts the create method call again, and this time the Bundle returns the value you saved in onSaveInstanceState
public void onCreate(Bundle icicle) { if (icicle != null){ value = icicle.getLong("param"); } }
source share