Cómo restaurar el estado de las vistas de fragmentos después de regresar de la pila posterior
Frecuentes
Visto 1,065 equipos
1
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?
1 Respuestas
0
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 android android-fragments fragment restore or haz tu propia pregunta.
Are you using setRetainInstance(true) in the fragment you put in backstack? - ILovemyPoncho
No, as far as I know it prevents fragment from switching resources on config change. - Lingviston
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. - ILovemyPoncho
That's what I mean - I need to restore views state. You know - textm scroll positions etc. - Lingviston
You can try to save that manually in onDestroyView() and restore it in onCreateView(). - ILovemyPoncho