dagger-2

How to pass a String to a ViewModel/Repository class using Dagger2 in Android?

拜拜、爱过 提交于 2019-12-11 15:59:40
问题 This is my fragment class: public class MyFragment extends DaggerFragment { @Inject MyViewModelFactory factory; @Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { String uid = "123"; //How to pass this String?? MyViewModel viewModel = ViewModelProviders.of(this, factory).get(MyViewModel.class); LiveData<User> liveData = viewModel.getUserLiveData(); } } Now this is MyViewModel class: public class MyViewModel extends ViewModel { private

How do you re-inject an android object, (Service, Activity…) being injected into by an AndroidInjector, into other objects?

感情迁移 提交于 2019-12-11 15:53:57
问题 I have a Service that has a DaggerServiceComponent that will inject all of the Services dependencies successfully. The problem is that I also have a ServiceManager class, which needs a reference to the Service in order to "Manage" service tasks. i.e. Application public class ApplicationBase extends Application implements HasServiceInjector { @Inject DispatchingAndroidInjector<Service> dispatchingAndroidServiceInjector; protected void setupServiceComponent(Context context) {

@Qualifier causes: [Dagger/MissingBinding] when field injecting

家住魔仙堡 提交于 2019-12-11 15:32:12
问题 I'm having this issue: ApplicationComponent.java:8: error: [Dagger/MissingBinding] @... java.text.SimpleDateFormat cannot be provided without an @Provides-annotated method. Module @Module abstract class ApplicationModule { @Binds @AppContext abstract fun application(app: App): Context @Module companion object { ... @Provides @Singleton @CalendarPickerDateFormat fun provideCalendarPickerDateFormat(): SimpleDateFormat { return SimpleDateFormat("dd/MMM/yyyy", Locale.getDefault()) } } } Qualifier

ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName androidx, running on andoridx crashes

跟風遠走 提交于 2019-12-11 14:41:55
问题 After Migrating to AndroidX(29) running on the AndroidX device Crashes showing ClassNotFoundException: config_inputEventCompatProcessorOverrideClassName the project compiles and runs it crashes when launched in andorid10.0 when clicked on the editText i get this error enter code here NullPointerException: Attempt to invoke virtual method 'java.util.List android.view.InputEventCompatProcessor.processInputEventForCompatibility(android.view.InputEvent)' on a null object reference project/build

Dagger 2: injecting singleton with lots of access points

大憨熊 提交于 2019-12-11 14:29:43
问题 I just started with DI / Dagger 2. I have a huge project. To try dagger 2, I started with injecting my singleton class 'MyPreferences'. This class handles all app actions from and to the SharedPreferences. Auto-injecting the SharedPreferences in the MyPreferences went perfectly. However, I am using this singleton in about 50 classes, I used to do this: MyPreferences.getInstance(context).getXXXSetting(); I have changed this to dagger2 injection in a few classes, and it works fine, but I find

Dagger 2: No implementation generated for component interface

北慕城南 提交于 2019-12-11 13:51:51
问题 I have created a demo Android Lib project and used dagger 2.0 with the following steps: Added the following jars to /libs folder: dagger-2.0.jar dagger-compiler-2.0.jar dagger-producers-2.0-beta.jar guava-18.0.jar javawriter-2.5.1.jar javax.annotation-api-1.2.jar javax.inject-1.jar Project -> Properties -> Java Compiler -> Annotation Processing (Enabled annotation processing) Project -> Properties -> Java Compiler -> Annotation Processing - Factory path: Added all the above mentioned jars.

How to make subcomponent singleton in dagger 2?

穿精又带淫゛_ 提交于 2019-12-11 13:29:46
问题 I want to make my subcomponent to be a singleton so that I can have Login Presenter to be a singleton as well. Is this possible? @Singleton @Component(modules = AppModule.class) public interface AppComponent { LoginComponent getLoginComponent(); } @Singleton @Subcomponent(modules = LoginModule.class) public interface LoginComponent { } public class LoginComponent { @Singleton LoginPresenter getLoginPresenter(); } 回答1: @Subcomponent s cannot be made @Singleton . While the @Singleton spec is a

Android dagger: No injector factory bound

三世轮回 提交于 2019-12-11 12:56:25
问题 I'm using dagger 2 on my android project. At first I'm use only one component in the name of AppComponent and my project works fine. Then I split AppComponent and create these component: ActivityComponent , ContentComponent for different scope. When I was build my project I getting an error: Caused by: java.lang.IllegalArgumentException: No injector factory bound for Class<project.presenter.activity.MainActivity> at dagger.android.DispatchingAndroidInjector.inject(DispatchingAndroidInjector

Dagger field injection not working with simple java classes

送分小仙女□ 提交于 2019-12-11 10:39:00
问题 I am trying field injection with dagger although constructor injection is working absolutely fine but i don't know what is wrong with field injection. May be I am doing wrong. I am adding the code snippets. I am getting null pointer exception on engine.start() because the engine dependency is not fed. It is similar to A->B->C dependencies where A->B is fed but B->C is not. Its been long I am unable to resolve. package com.raghav.java.car; import javax.inject.Inject; public class App { @Inject

In dagger 2, Is it possible to do field injection and constructor injection for the same class?

徘徊边缘 提交于 2019-12-11 10:31:51
问题 Is it possible to do field injection and constructor injection for the same class ? For instance : implementation is like activity field injection of fragment. fragment (activityscoped) non parameter constructor injection (downstream ) field injection of presenter(Fragmentscoped) class. 回答1: Yes, you can inject constructors, methods, and fields within the same class. Dagger will automatically inject fields and call @Inject -annotated methods as part of the construction process. 来源: https:/