Android activities have a pair of methods onRetainNonConfigurationInstance()/getLastNonConfigurationInstance() for keeping objects expensive for l开发者_Go百科oad during configuration changes.
What should be a nice behavior for fragments in such case? Is setRetainInstance() a solution? What about usage of configuration-specific resources after setting it to true?
Thank you.
If you need to support orientation change, say because you need a different layout, then I have found setRetainInstance
works for me making use of onSaveInstanceState
if need be, using the saved state info inonCreateView
or onActivityCreated
.
With regard configuration specific resources, these won't be affected by setting setRetainInstance
you'll still get access to the correct resources for your orientation etc.in onCreateView
and so forth after an orientation change.
Do you really have to support orientation changes?
If not, you can override this behavior in your AndroidManifest-file.
精彩评论