Karthik Andhamil
Karthik Andhamil

Reputation: 856

Android ListFragment invoked twice

When I start a fragment from the activity, The methods onCreate(), onViewCreated() are invoked twice.

Here's my code:

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chapter_list);

    FragmentManager frgManager = getSupportFragmentManager();
    if (findViewById(R.id.fl_chapter_detail) != null)
    {
        mbThreePaneLayout = true;
        FragmentChapterList frgChapterList = (FragmentChapterList) frgManager.findFragmentById(R.id.frg_chapter_list);
        frgChapterList.setActivateOnItemClick(true);
    }

    if (savedInstanceState == null)
    {
        String strSelectedSection = getIntent().getStringExtra(Konstant.KEY_SELECTED_SECTION);

        if (((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) != Configuration.SCREENLAYOUT_SIZE_XLARGE) || (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT))
            currentActionBar.setTitle(strSelectedSection);

        Bundle arguments = new Bundle();
        arguments.putString(Konstant.KEY_SELECTED_SECTION, strSelectedSection);

        FragmentChapterList frgChapterList = new FragmentChapterList();
        frgChapterList.setArguments(arguments);

        FragmentTransaction frgTransaction = frgManager.beginTransaction();
        frgTransaction.add(R.id.frg_chapter_list, frgChapterList).commit();
    }
}

Does anyone have idea why it's happening?

Upvotes: 0

Views: 211

Answers (1)

Alex Gittemeier
Alex Gittemeier

Reputation: 5373

To fix this:

  • Change the type of tag for the fragment from <fragment /> to a placeholder, such as <FrameLayout />.
  • Remove the name attribute.

For more information see: InflateException Caused by <fragment> Tag Without a Bound Class

Upvotes: 2

Related Questions