Handling_Runtime_Changes

app need to Handling Runtime Changes such as [keyboard|keyboardhide|oritation].

1. if app doesn’t explicitely handle such changes, android does

android(ActivityStack.java##ensureActivityConfigurationLocked()) will restart the running Activity (onDestroy()->onCreate()), so app needs to implement onSaveInstanceState(),

2. else app need to explicitely handle changes

2.1 Retain an object during a configuration change

allow activity restart, but carry a stateful object to the new activity instance, read this

2.2 Handle the configuration change yourself

disable activity restart, handle the config change event in a callback.

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);

// Checks the orientation of the screen
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){
Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}

This is a list of all android:configChanges events and the Configuration class.