Issue
This is really a two questions pertaining to lifecycle.
1) In Fragment.onCreateView(LayoutInflater, ViewGroup container, Bundle), all of the examples I've seen simply use the LayoutInflater to inflate a View, and return it. If this is part of a Restore though, i.e. non-null Bundle, shouldn't the restoration of the view hierarchy be handled by the system? Should I instead be calling container.findViewById() or trying to pull the view out of the Bundle or something (for the purposes of pulling out references to subviews)?
2) In general, do any of the Fragment lifecycle callbacks need to worry about saving/restoring the state of its view hierarchy, even implicitly by calling super.onXXX()? Or is that all handled uplevel by the owning Activity when it calls super.onCreate(Bundle)?
Solution
Although the framework is responsible for re-creating the
Fragment
itself, the view hierarchy must be recreated manually. Views cannot survive the destruction of theirActivity
(plus, sinceonCreateView()
has your implementation, you could conditionally inflate another layout or do different things -- that's why it has to run every time). The Bundle contains information put there byonSaveInstanceState()
, but the old views are not part of it.If the view ids match between the old and new layout, then the state should be automatically restored (via the super calls). Views override their own
onSaveInstanceState()
for this. If you save your custom state in the fragment'sonSaveInstanceState()
, then you're also responsible for restoring it.
Answered By - matiash
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.