oxot
30/08/17, 18:34:45
Voy a intentar resumirlo lo más posible para no hacerlo engorroso. Tengo una app que me ha dado un error (no consigo reproducirlo, es la primera vez que da en varios años, espero que no dé muchas más veces) que me tiene con las mosca de la curiosidad.
Este es el error:
Fatal Exception: java.lang.IllegalStateException: Failure saving state: AlertDialogFragment{1232b423 #4 AlertDialog} has target not in fragment manager: ListaFragment{288b8d20}
at android.app.FragmentManagerImpl.saveAllState(Fragm entManager.java:1666)
at android.app.Activity.onSaveInstanceState(Activity. java:1397)
at android.support.v4.app.FragmentActivity.onSaveInst anceState(FragmentActivity.java:570)
at android.support.v7.app.AppCompatActivity.onSaveIns tanceState(AppCompatActivity.java:509)
at com.miproyecto.Container.onSaveInstanceState(Conta iner.java:476)
O sea, al salvar el estado de la app, tengo un DialogFragment abierto con un target que es el Fragment que creó este diálogo y que ya no existe!! El fragment que creó el diálogo ha dejado de estar en el FM.
Según el código fuente de Android:
Parcelable More ...saveAllState() {
1633 // Make sure all pending operations have now been executed to get
1634 // our state update-to-date.
1635 execPendingActions();
1636
1637 mStateSaved = true;
1638
1639 if (mActive == null || mActive.size() <= 0) {
1640 return null;
1641 }
1642
1643 // First collect all active fragments.
1644 int N = mActive.size();
1645 FragmentState[] active = new FragmentState[N];
1646 boolean haveFragments = false;
1647 for (int i=0; i<N; i++) {
1648 Fragment f = mActive.get(i);
1649 if (f != null) {
1650 if (f.mIndex < 0) {
1651 throwException(new IllegalStateException(
1652 "Failure saving state: active " + f
1653 + " has cleared index: " + f.mIndex));
1654 }
1655
1656 haveFragments = true;
1657
1658 FragmentState fs = new FragmentState(f);
1659 active[i] = fs;
1660
1661 if (f.mState > Fragment.INITIALIZING && fs.mSavedFragmentState == null) {
1662 fs.mSavedFragmentState = saveFragmentBasicState(f);
1663
1664 if (f.mTarget != null) {
1665 if (f.mTarget.mIndex < 0) {
1666 throwException(new IllegalStateException(
1667 "Failure saving state: " + f
1668 + " has target not in fragment manager: " + f.mTarget));
1669 }
Como véis, el DialogFragment está activo, mira si tiene un Target, y mira el mIndex de ese Targer (ListaFragment) y resulta que su mIndex < 0, lo que implica que ya no está en la lista de activos.
La pregunta:
¿Se os ocurre cuándo un fragment puede no estar activo mientres sigue activo el dialogfragment que hemos creado desde ese fragment?
No consigo reproducir el fallo :loco::loco::loco:
Y como siempre, :gracias:
Este es el error:
Fatal Exception: java.lang.IllegalStateException: Failure saving state: AlertDialogFragment{1232b423 #4 AlertDialog} has target not in fragment manager: ListaFragment{288b8d20}
at android.app.FragmentManagerImpl.saveAllState(Fragm entManager.java:1666)
at android.app.Activity.onSaveInstanceState(Activity. java:1397)
at android.support.v4.app.FragmentActivity.onSaveInst anceState(FragmentActivity.java:570)
at android.support.v7.app.AppCompatActivity.onSaveIns tanceState(AppCompatActivity.java:509)
at com.miproyecto.Container.onSaveInstanceState(Conta iner.java:476)
O sea, al salvar el estado de la app, tengo un DialogFragment abierto con un target que es el Fragment que creó este diálogo y que ya no existe!! El fragment que creó el diálogo ha dejado de estar en el FM.
Según el código fuente de Android:
Parcelable More ...saveAllState() {
1633 // Make sure all pending operations have now been executed to get
1634 // our state update-to-date.
1635 execPendingActions();
1636
1637 mStateSaved = true;
1638
1639 if (mActive == null || mActive.size() <= 0) {
1640 return null;
1641 }
1642
1643 // First collect all active fragments.
1644 int N = mActive.size();
1645 FragmentState[] active = new FragmentState[N];
1646 boolean haveFragments = false;
1647 for (int i=0; i<N; i++) {
1648 Fragment f = mActive.get(i);
1649 if (f != null) {
1650 if (f.mIndex < 0) {
1651 throwException(new IllegalStateException(
1652 "Failure saving state: active " + f
1653 + " has cleared index: " + f.mIndex));
1654 }
1655
1656 haveFragments = true;
1657
1658 FragmentState fs = new FragmentState(f);
1659 active[i] = fs;
1660
1661 if (f.mState > Fragment.INITIALIZING && fs.mSavedFragmentState == null) {
1662 fs.mSavedFragmentState = saveFragmentBasicState(f);
1663
1664 if (f.mTarget != null) {
1665 if (f.mTarget.mIndex < 0) {
1666 throwException(new IllegalStateException(
1667 "Failure saving state: " + f
1668 + " has target not in fragment manager: " + f.mTarget));
1669 }
Como véis, el DialogFragment está activo, mira si tiene un Target, y mira el mIndex de ese Targer (ListaFragment) y resulta que su mIndex < 0, lo que implica que ya no está en la lista de activos.
La pregunta:
¿Se os ocurre cuándo un fragment puede no estar activo mientres sigue activo el dialogfragment que hemos creado desde ese fragment?
No consigo reproducir el fallo :loco::loco::loco:
Y como siempre, :gracias: