Using activity level dependencies in fragments with dagger2What is dependency injection?How do save an Android Activity state using save instance state?Activity restart on rotation AndroidStop EditText from gaining focus at Activity startupInversion of Control vs Dependency InjectionDagger2 dependent componentsRequestQueue cannot be provided without an inject constructorAndroid-Dagger2 - Can't get dependencies from Application component into Activity ScopeDagger2 can not provide dependancyDagger2 injects null object

Lowest total scrabble score

Is it better practice to read straight from sheet music rather than memorize it?

A social experiment. What is the worst that can happen?

Where does the bonus feat in the cleric starting package come from?

Argument list too long when zipping large list of certain files in a folder

Count the occurrence of each unique word in the file

Is it possible to put a rectangle as background in the author section?

What should you do when eye contact makes your subordinate uncomfortable?

What if a revenant (monster) gains fire resistance?

Can I sign legal documents with a smiley face?

Can someone explain how this makes sense electrically?

Is this toilet slogan correct usage of the English language?

What should you do if you miss a job interview (deliberately)?

How do you respond to a colleague from another team when they're wrongly expecting that you'll help them?

Loading commands from file

How should I respond when I lied about my education and the company finds out through background check?

I am looking for the correct translation of love for the phrase "in this sign love"

What prevents the use of a multi-segment ILS for non-straight approaches?

Has any country ever had 2 former presidents in jail simultaneously?

Is the U.S. Code copyrighted by the Government?

Is it safe to use olive oil to clean the ear wax?

Redundant comparison & "if" before assignment

What was the exact wording from Ivanhoe of this advice on how to free yourself from slavery?

Why does the Sun have different day lengths, but not the gas giants?



Using activity level dependencies in fragments with dagger2


What is dependency injection?How do save an Android Activity state using save instance state?Activity restart on rotation AndroidStop EditText from gaining focus at Activity startupInversion of Control vs Dependency InjectionDagger2 dependent componentsRequestQueue cannot be provided without an inject constructorAndroid-Dagger2 - Can't get dependencies from Application component into Activity ScopeDagger2 can not provide dependancyDagger2 injects null object













0















I have a project structure like this:



@Component(modules = AndroidSupportInjectionModule.class, AppModule.class, 
ActivityBinderModule.class)
public interface ApplicationComponent extends AndroidInjector<MyApplication>
...


I have a bunch of app level dependencies defined in AppModule



@Module
public abstract class ActivityBinderModule

@ActivityScope
@ContributesAndroidInjector(modules = MainActivityModule.class, FragmentBinderModule.class)
abstract MainActivity bindMainActivity();



I have some activity level dependencies defined in MainActivityModule, e.g. the FragmentManager



@Module
public abstract class FragmentBinderModule

@ContributesAndroidInjector(modules = MainPageModule.class)
@FragmentScope
abstract MainPageFragment provideMainPageFragment();



I have the MainPageFragment specific dependencies defined in MainPageModule, like DialogFactory (scoped with @FragmentScope), which needs a FragmentManager



I would like to use the FragmentManager instance provided by MainActivityModule in DialogFactory, but I got the error:



FragmentManager cannot be provided without an @Provides-annotated method.



When I add a provider for the FragmentManager in MainPageModule, I get this error:



FragmentManager is bound multiple times: MainActivityModule and MainPageModule



What am I doing wrong?










share|improve this question






















  • Is FragmentManager the Android FragmentManager or some class of yours ?

    – Blackbelt
    2 days ago











  • the Android one, SupportFragmentManager

    – Analizer
    2 days ago











  • why do you need dagger to provide that for you?

    – Blackbelt
    2 days ago











  • So I can just inject it to all the classes needing it, but my question is a bit bigger then that, I could have asked it more generally: How can I inject Activity level dependencies into Fragment level objects?, this was just the example triggering it

    – Analizer
    2 days ago












  • in your case you have to different modules providing the same dependency (FragmentManager). To circumvent the error you can use the @Named annotation. In the specific case, I don't see the reason to inject something, the system provides already.

    – Blackbelt
    2 days ago
















0















I have a project structure like this:



@Component(modules = AndroidSupportInjectionModule.class, AppModule.class, 
ActivityBinderModule.class)
public interface ApplicationComponent extends AndroidInjector<MyApplication>
...


I have a bunch of app level dependencies defined in AppModule



@Module
public abstract class ActivityBinderModule

@ActivityScope
@ContributesAndroidInjector(modules = MainActivityModule.class, FragmentBinderModule.class)
abstract MainActivity bindMainActivity();



I have some activity level dependencies defined in MainActivityModule, e.g. the FragmentManager



@Module
public abstract class FragmentBinderModule

@ContributesAndroidInjector(modules = MainPageModule.class)
@FragmentScope
abstract MainPageFragment provideMainPageFragment();



I have the MainPageFragment specific dependencies defined in MainPageModule, like DialogFactory (scoped with @FragmentScope), which needs a FragmentManager



I would like to use the FragmentManager instance provided by MainActivityModule in DialogFactory, but I got the error:



FragmentManager cannot be provided without an @Provides-annotated method.



When I add a provider for the FragmentManager in MainPageModule, I get this error:



FragmentManager is bound multiple times: MainActivityModule and MainPageModule



What am I doing wrong?










share|improve this question






















  • Is FragmentManager the Android FragmentManager or some class of yours ?

    – Blackbelt
    2 days ago











  • the Android one, SupportFragmentManager

    – Analizer
    2 days ago











  • why do you need dagger to provide that for you?

    – Blackbelt
    2 days ago











  • So I can just inject it to all the classes needing it, but my question is a bit bigger then that, I could have asked it more generally: How can I inject Activity level dependencies into Fragment level objects?, this was just the example triggering it

    – Analizer
    2 days ago












  • in your case you have to different modules providing the same dependency (FragmentManager). To circumvent the error you can use the @Named annotation. In the specific case, I don't see the reason to inject something, the system provides already.

    – Blackbelt
    2 days ago














0












0








0








I have a project structure like this:



@Component(modules = AndroidSupportInjectionModule.class, AppModule.class, 
ActivityBinderModule.class)
public interface ApplicationComponent extends AndroidInjector<MyApplication>
...


I have a bunch of app level dependencies defined in AppModule



@Module
public abstract class ActivityBinderModule

@ActivityScope
@ContributesAndroidInjector(modules = MainActivityModule.class, FragmentBinderModule.class)
abstract MainActivity bindMainActivity();



I have some activity level dependencies defined in MainActivityModule, e.g. the FragmentManager



@Module
public abstract class FragmentBinderModule

@ContributesAndroidInjector(modules = MainPageModule.class)
@FragmentScope
abstract MainPageFragment provideMainPageFragment();



I have the MainPageFragment specific dependencies defined in MainPageModule, like DialogFactory (scoped with @FragmentScope), which needs a FragmentManager



I would like to use the FragmentManager instance provided by MainActivityModule in DialogFactory, but I got the error:



FragmentManager cannot be provided without an @Provides-annotated method.



When I add a provider for the FragmentManager in MainPageModule, I get this error:



FragmentManager is bound multiple times: MainActivityModule and MainPageModule



What am I doing wrong?










share|improve this question














I have a project structure like this:



@Component(modules = AndroidSupportInjectionModule.class, AppModule.class, 
ActivityBinderModule.class)
public interface ApplicationComponent extends AndroidInjector<MyApplication>
...


I have a bunch of app level dependencies defined in AppModule



@Module
public abstract class ActivityBinderModule

@ActivityScope
@ContributesAndroidInjector(modules = MainActivityModule.class, FragmentBinderModule.class)
abstract MainActivity bindMainActivity();



I have some activity level dependencies defined in MainActivityModule, e.g. the FragmentManager



@Module
public abstract class FragmentBinderModule

@ContributesAndroidInjector(modules = MainPageModule.class)
@FragmentScope
abstract MainPageFragment provideMainPageFragment();



I have the MainPageFragment specific dependencies defined in MainPageModule, like DialogFactory (scoped with @FragmentScope), which needs a FragmentManager



I would like to use the FragmentManager instance provided by MainActivityModule in DialogFactory, but I got the error:



FragmentManager cannot be provided without an @Provides-annotated method.



When I add a provider for the FragmentManager in MainPageModule, I get this error:



FragmentManager is bound multiple times: MainActivityModule and MainPageModule



What am I doing wrong?







android dependency-injection dagger-2






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked 2 days ago









AnalizerAnalizer

9401022




9401022












  • Is FragmentManager the Android FragmentManager or some class of yours ?

    – Blackbelt
    2 days ago











  • the Android one, SupportFragmentManager

    – Analizer
    2 days ago











  • why do you need dagger to provide that for you?

    – Blackbelt
    2 days ago











  • So I can just inject it to all the classes needing it, but my question is a bit bigger then that, I could have asked it more generally: How can I inject Activity level dependencies into Fragment level objects?, this was just the example triggering it

    – Analizer
    2 days ago












  • in your case you have to different modules providing the same dependency (FragmentManager). To circumvent the error you can use the @Named annotation. In the specific case, I don't see the reason to inject something, the system provides already.

    – Blackbelt
    2 days ago


















  • Is FragmentManager the Android FragmentManager or some class of yours ?

    – Blackbelt
    2 days ago











  • the Android one, SupportFragmentManager

    – Analizer
    2 days ago











  • why do you need dagger to provide that for you?

    – Blackbelt
    2 days ago











  • So I can just inject it to all the classes needing it, but my question is a bit bigger then that, I could have asked it more generally: How can I inject Activity level dependencies into Fragment level objects?, this was just the example triggering it

    – Analizer
    2 days ago












  • in your case you have to different modules providing the same dependency (FragmentManager). To circumvent the error you can use the @Named annotation. In the specific case, I don't see the reason to inject something, the system provides already.

    – Blackbelt
    2 days ago

















Is FragmentManager the Android FragmentManager or some class of yours ?

– Blackbelt
2 days ago





Is FragmentManager the Android FragmentManager or some class of yours ?

– Blackbelt
2 days ago













the Android one, SupportFragmentManager

– Analizer
2 days ago





the Android one, SupportFragmentManager

– Analizer
2 days ago













why do you need dagger to provide that for you?

– Blackbelt
2 days ago





why do you need dagger to provide that for you?

– Blackbelt
2 days ago













So I can just inject it to all the classes needing it, but my question is a bit bigger then that, I could have asked it more generally: How can I inject Activity level dependencies into Fragment level objects?, this was just the example triggering it

– Analizer
2 days ago






So I can just inject it to all the classes needing it, but my question is a bit bigger then that, I could have asked it more generally: How can I inject Activity level dependencies into Fragment level objects?, this was just the example triggering it

– Analizer
2 days ago














in your case you have to different modules providing the same dependency (FragmentManager). To circumvent the error you can use the @Named annotation. In the specific case, I don't see the reason to inject something, the system provides already.

– Blackbelt
2 days ago






in your case you have to different modules providing the same dependency (FragmentManager). To circumvent the error you can use the @Named annotation. In the specific case, I don't see the reason to inject something, the system provides already.

– Blackbelt
2 days ago













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281334%2fusing-activity-level-dependencies-in-fragments-with-dagger2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55281334%2fusing-activity-level-dependencies-in-fragments-with-dagger2%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript