I want to understand the reason why request feature must be called before setting a view in android activity
-
duplicate http://stackoverflow.com/questions/4250149/requestfeature-must-be-called-before-adding-content – Rustam Oct 24 '14 at 15:24
1 Answers
From the documentation:
Enable extended screen features. This must be called before setContentView(). May be called as many times as desired as long as it is before setContentView(). If not called, no extended features will be available. You can not turn off a feature once it is requested. You canot use other title features with FEATURE_CUSTOM_TITLE.
requestFeature modifies the window that you are inflating a view on. The window must be set before you can inflate a view on it which is what setContentView does. In layman's terms, you wouldn't try to hang blinds before you put the window into a wall right?
When the view inflates it needs the window to be set and stable so it can properly calculate where to put items. If the window is not constant then the content view would have to be reinflated after every requestFeature. If Android did not enforce the rule of requestFeature before setContentView, on every requestFeature the view would be reinstalled and the end result would most likely be the screen flickering a few times as the view gets reinflated time and time again.

- 2,181
- 6
- 27
- 36