Cómo restaurar el estado de las vistas de fragmentos después de regresar de la pila posterior

He Fragment which I replace by another one. I put transaction to backstack so I can move back later. If I press back button saveInstanceState Bundle of restored Fragment is null in it's methods cause saveInstanceState método de Fragment is actually called when parent Activity instance destroyed. So how I must restore Fragment state after returning it from backstack?

preguntado el 12 de junio de 14 a las 11:06

Are you using setRetainInstance(true) in the fragment you put in backstack? -

No, as far as I know it prevents fragment from switching resources on config change. -

I'm not sure what's the problem then. You want to restore the fragment that was put in the backstack, even when the configuration never changed (onSaveInstanceState() not called)? You don't need to restore it, the fragment instance still exists, only its view hierarchy was destroyed. -

That's what I mean - I need to restore views state. You know - textm scroll positions etc. -

You can try to save that manually in onDestroyView() and restore it in onCreateView(). -

1 Respuestas

This problem was mostly related to ListViews. I have found a solution in more correct managing of adapter data. I had local mAdapter variable en mi Fragment which was created, populated with data and set to ListView in onResume() método de mi Fragment. I have found solution in moving this code into onActivityCreated() método.

Respondido el 29 de enero de 15 a las 22:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.