2

I am having an issue in one of my fragments which contains a TabLayout. The TabLayout and the data inside each tab works fine but I still get a moveToState error (This error does not come up when I switch between the first and last one, only from first to middle and last to middle). My application still works fine with the error but I would much rather get rid of it to avoid any possibly future complications.

LOGCAT

04-23 00:08:04.064 1598-1598/org.ramferno.scoutapplication.ramfernoscout W/FragmentManager: moveToState: Fragment state for TeamInfoTabOneFragment{1788a4f #9 id=0x7f0c00ca} not updated inline; expected state 3 found 2
04-23 00:12:56.007 1598-1598/org.ramferno.scoutapplication.ramfernoscout W/FragmentManager: moveToState: Fragment state for TeamInfoTabThreeFragment{29125dc #7 id=0x7f0c00ca} not updated inline; expected state 3 found 2

TeamInfoFragment.java (With tabLayout)

package org.ramferno.scoutapplication.ramfernoscout.fragments;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.ramferno.scoutapplication.ramfernoscout.adapters.InfoPagerAdapter;
import org.ramferno.scoutapplication.ramfernoscout.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class TeamInfoFragment extends Fragment {
    TabLayout tabLayout;
    ViewPager viewPager;
    InfoPagerAdapter infoPagerAdapter;

    public TeamInfoFragment() {
        // Required empty public constructor
    } //End of TeamInfoFragment

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_team_info, container, false);

        //Initializes variables
        tabLayout = (TabLayout) view.findViewById(R.id.infoTabLayout);
        viewPager = (ViewPager) view.findViewById(R.id.infoPager);

        //Adds tabs to viewPager
        infoPagerAdapter = new InfoPagerAdapter(getFragmentManager());
        infoPagerAdapter.addFragments(new TeamInfoTabOneFragment(), "Team Info");
        infoPagerAdapter.addFragments(new TeamInfoTabTwoFragment(), "Achievements");
        infoPagerAdapter.addFragments(new TeamInfoTabThreeFragment(), "Past Tournaments");

        //Sets adapter for viewPager then sets the same view pager for tabLayout
        viewPager.setAdapter(infoPagerAdapter);
        tabLayout.setupWithViewPager(viewPager);

        return view;
    } //End of onCreateView
} //End of class

InfoPagerAdapter.java

package org.ramferno.scoutapplication.ramfernoscout.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import java.util.ArrayList;

public class InfoPagerAdapter extends FragmentStatePagerAdapter {
    ArrayList<Fragment> fragments = new ArrayList<>();
    ArrayList<String> tabTitles = new ArrayList<>();

    public void addFragments(Fragment fragments, String titles) {
        this.fragments.add(fragments);
        this.tabTitles.add(titles);
    } //End of addFragments

    public InfoPagerAdapter(FragmentManager fm) {
        super(fm);
    } //End of InfoPagerAdapter

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    } //End of getItem

    @Override
    public int getCount() {
        return fragments.size();
    } //Edn of getCount

    public CharSequence getPageTitle(int position) {
        return tabTitles.get(position);
    } //End of getPageTitle
} //End of class

Please notify me if anymore information is required.

Samer Alabi
  • 117
  • 1
  • 10

1 Answers1

1

This is an informational log message only... There is an issue about it.

Project Member #14 ad...@android.com Nope, it doesn't matter and the extra log will be gone in a future release.

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.

Sorry for the extra log noise :)

pppery
  • 3,731
  • 22
  • 33
  • 46
Pedr
  • 11
  • 1
  • 2