question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why I can't add a instance of Fragment?

See original GitHub issue

This can be a problem:

add(int title, java.lang.Class<? extends android.support.v4.app.Fragment> clazz)

I need to have a:

add(int title, Fragment fragment)

Why, If I need create a instance of the Fragment, I need use this.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ogaclejapancommented, Apr 23, 2015

Please try checked Don’t keep activities in the developer mode. When you view again after returning to the home, it will change to a different instance. Often occurs is similar events in low memory device.


    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Object item = super.instantiateItem(container, position);
        Log.d("DEBUG", "position: " + position + " " + item.toString());
        if (item instanceof Fragment) {
            mHolder.put(position, new WeakReference<Fragment>((Fragment) item));
        }
        return item;
    }

0reactions
ppamorimcommented, May 15, 2015

Solved!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot add Fragment on android - java - Stack Overflow
The problem is that you're using : import android.app.FragmentManager; import android.app.FragmentTransaction;. And your Fragment class ...
Read more >
Creating and Using Fragments | CodePath Android Cliffnotes
Fragments must be embedded in activities ; they cannot run independently of ... There are two ways to add a fragment to an...
Read more >
Create a fragment - Android Developers
A fragment has its own lifecycle, receives its own input events, and you can add or remove fragments while the containing activity is...
Read more >
New viewmodel for every instance of same fragment #145
It opens a new instance of PersonFragment but gets the viewmodel of the previous PersonFragment; The app crashes with the following exception.
Read more >
Android Fragments: FragmentContainerView - ProAndroidDev
When a Fragment's view is being created, a tag is assigned to it in order to associate it with the Fragment instance, this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found