Probably it is a well-known topic, but I didn't find any "universal" solution.
The main problems are two:
- When a
fragment
is put tobackstack
,onSavedInstanceState
is never called - Why can't you instantiate
fragment's
views inonCreate
?
And at this point my question is: since the fragment lifecycle
goes through onCreateView
every resume
, and since we can't instantiate views
in onCreate
; why do we have to re-create views
every time the fragment
is shown? There must be a way as in the Activity
with onCreate
.
We might avoid by adding a class-scoped boolean
and check if it has a value, but it means adding an if
and this can't be the best solution. Another solution might be this one, but it is also a workaround and it also has some limitations.
Is there a built-in (or a standard) solution that solve this problem?