We are using Fragments and we don't need them to be automatically recovered when the Activity is recreated.
But Android every time when Activity::onCreate(Bundle savedInstanceState)
-> super.onCreate(savedInstanceState)
is called, restores Fragments even if we use setRetainInstance(false) for those Fragments.
Moreover, in those Fragments
Fragment.performCreateView()
is called directly without going through Fragment::onAttach()
and so on. Plus, some of the fields are null inside restored Fragment
...
Does anybody know how to prevent Android from restoring fragments?
P.S. We know that in case of recreating Activity for config changes it could be done by adding to manifest android:configChanges="orientation|screenSize|screenLayout
. But what about recreating activity in case of automatic memory cleaning?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…