I programmatically create a RelativeLayout with some other views inside it and add it to the parent which is defined in XML. But all the views (incl. the layout) that were creat
I recommend you look into Activity.onSaveInstanceState(Bundle)
:
The default implementation takes care of most of the UI per-instance state for you by calling onSaveInstanceState() on each view in the hierarchy that has an id, and by saving the id of the currently focused view (all of which is restored by the default implementation of onRestoreInstanceState()). If you override this method to save additional information not captured by each individual view, you will likely want to call through to the default implementation [ via
super.onSaveInstanceState()
andsuper.onRestoreInstanceState()
], otherwise be prepared to save all of the state of each view yourself.
https://developer.android.com/reference/android/app/Activity.html#onSaveInstanceState(android.os.Bundle)
as well as my answer here:
How can I assign an ID to a view programmatically?