-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support injecting FragmentManager in FragmentActivity #42
Comments
My use case of FragmentManager is more complicated.
MyFragmentStatePagerAdapter:
This should be a very typical usage. For this case, the FragmentManager is not really use in the Is possible for MyFragmentStatePagerAdapter to get the "closest" FragmentActivity? (without a defined module) If it is supposed, we probably need to document it clearly so people can have a clue about where the FragmentManager comes from. |
Right now FragmentManager is available if you extend the For your use case, could you try injecting the FragmentActivity into your FragmentStatePagerAdapter, and then getting the FragmentManager from there: class MyFragmentStatePagerAdapter extends FragmentStatePagerAdapter {
@Inject public MyFragmentStatePagerAdapter(FragmentActivity fragmentActivity) {
super(fragmentActivity.getFragmentManager()); //constructor required by super class
}
} I think this should do the work you mentioned of getting the "closest" FragmentActivity. Let me know if this works for you and I'll see about making the FragmentManager move available. |
yes, it works. Better to inject FragmentActivity than use a Module. thx p.s. I don't think better support for FragmentManager injection should be in a high priority. |
I'm going to leave this open as a reminder. |
There is an example that in a
@Fragment
class, it supports@Inject FragmentManager
.In a
@Activity(type=FragmentActivity.class)
class, it doesn't support injecting FragmentManager, and I expect it inject thegetSupportingFragmentManager
. Instead, it generated code that donew FragmentManager()
.As a workaround, we can do:
I do it in a similar way in Dagger, but I think Transfuse may potentially make it even simpler without the need to create a Module.
The text was updated successfully, but these errors were encountered: