Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FragmentManager: moveToState: Fragment state for GridFragment{...} not updated inline; expected state 1 found 0

I have a simple Activity and Retained Fragment, just as Alex Lockwood blog post example.

My activity goes like this inside onCreate():

FragmentManager fm = getSupportFragmentManager();
    retainedFragment = (GridFragment) fm.findFragmentByTag(RETAINED_FRAGMENT_TAG);

    // If the Fragment is non-null, then it is currently being
    // retained across a configuration change.
    if (retainedFragment == null) {
        retainedFragment = new GridFragment();
        fm.beginTransaction().add(retainedFragment, RETAINED_FRAGMENT_TAG).commit();
    }else{
        list = retainedFragment.getList();
        System.out.println(list.size());//OUTPUT 12
    }

And my Fragments' onAttach() is :

 @Override
public void onAttach(Context activity) {
    super.onAttach(activity);
    mCallbacks = (TaskCallbacks) activity;
    System.out.println("here"); //OUTPUT here
}

Now, on every screen rotation I've got very strange output:

I/System.out: here

W/FragmentManager: moveToState: Fragment state for GridFragment{95fc9db #0 retained_tag} not updated inline; expected state 1 found 0

I/System.out: 12

Where is that strange warning comes from right between my inputs? How to deal with it? Thanks in advance!

like image 383
Evgeniy Mishustin Avatar asked May 09 '16 21:05

Evgeniy Mishustin


1 Answers

This message doesn't matter and the extra log was removed in Support Library v24.0.0 This is official developer answer:

For the curious, FragmentManager.moveToState now updates the new fragment state as it goes rather than at the end after all of the state change phases have completed. This fixed several interesting bugs around using the child fragment manager and executePendingTransactions from within one of the parent fragment's lifecycle callbacks.

One of the state transitions as we're bringing a fragment up is a no-op that wasn't getting the state updated inline, and the log you're seeing is announcing that we did it at the end instead, exactly as we would have prior to 23.2.

like image 78
mbelsky Avatar answered Oct 07 '22 23:10

mbelsky