dagger

Dagger2 - How to use @Named with @BindsInstance

六眼飞鱼酱① 提交于 2020-07-21 07:30:28
问题 How is @Named used with @BindsInstance? I have the this component interface AppComponent : AndroidInjector<MyApplication>{ @Component.Builder abstract class Builder : AndroidInjector.Builder<MyApplication>() { @BindsInstance abstract fun preferenceName( @Named("PreferenceName") name : String ) : Builder } } and trying to inject in MyApplication @Inject @Named("PreferenceName") lateinit var prefName : String But it fails with MissingBinding for String. I could resolve this with a module

Error [Dagger/MissingBinding] androidx.lifecycle.ViewModelProvider.Factory cannot be provided without an @Provides-annotated method

淺唱寂寞╮ 提交于 2020-07-21 07:11:10
问题 I am facing an issue while implementing MultiBinding using dagger 2.2. I am using dagger with MVVM architecture. I have injected the ViewModelProvideFactory constructor and binds the dependency from module. I have followed the tutorial of Mitch from youtube https://www.youtube.com/watch?v=DToD1W9WdsE&list=PLgCYzUzKIBE8AOAspC3DHoBNZIBHbIOsC&index=13 I have searched on these links for the solutions but still facing the same issue. Dagger2: ViewModel cannot be provided without an @Provides

CustomScope may not reference bindings with different scopes

拥有回忆 提交于 2020-06-23 05:56:27
问题 I am new to dagger, I have defined my application component like this @Singleton @Component(modules = {ApplicationModule.class}) public interface ApplicationComponent { void inject(BaseActivity activity); Context context(); } This is my ApplicationModule @Module public class ApplicationModule { public TipoApplication application; public ApplicationModule(TipoApplication application) { this.application = application; } @Singleton @Provides public Context provideContext(){return application

CustomScope may not reference bindings with different scopes

帅比萌擦擦* 提交于 2020-06-23 05:56:05
问题 I am new to dagger, I have defined my application component like this @Singleton @Component(modules = {ApplicationModule.class}) public interface ApplicationComponent { void inject(BaseActivity activity); Context context(); } This is my ApplicationModule @Module public class ApplicationModule { public TipoApplication application; public ApplicationModule(TipoApplication application) { this.application = application; } @Singleton @Provides public Context provideContext(){return application

Inject only certain params in constructor

时光总嘲笑我的痴心妄想 提交于 2020-06-12 06:52:27
问题 I have the presenter class PhonePresenter @Inject constructor( private val preference: DataPreference, private val ioScheduler: Scheduler = Schedulers.io()) ioScheduler is a default parameter. I want to inject only preference: DataPreference . Now I have the exception [dagger.android.AndroidInjector.inject(T)] io.reactivex.Scheduler cannot be provided without an @Provides-annotated method. Is there any way to define parameters which I want to inject in a constructor? 回答1: Make inject

Dagger 2 - two provides method that provide same interface

亡梦爱人 提交于 2020-05-22 13:35:12
问题 lets say I have: public interface Shape {} public class Rectangle implements Shape { } public class Circle implements Shape { } and I have a ApplicationModule which needs to provides instances for both Rec and Circle : @Module public class ApplicationModule { private Shape rec; private Shape circle; public ApplicationModule() { rec = new Rectangle(); circle= new Circle (); } @Provides public Shape provideRectangle() { return rec ; } @Provides public Shape provideCircle() { return circle; } }

Dagger 2 - two provides method that provide same interface

夙愿已清 提交于 2020-05-22 13:34:59
问题 lets say I have: public interface Shape {} public class Rectangle implements Shape { } public class Circle implements Shape { } and I have a ApplicationModule which needs to provides instances for both Rec and Circle : @Module public class ApplicationModule { private Shape rec; private Shape circle; public ApplicationModule() { rec = new Rectangle(); circle= new Circle (); } @Provides public Shape provideRectangle() { return rec ; } @Provides public Shape provideCircle() { return circle; } }

@Binds methods must have only one parameter whose type is assignable to the return type

蹲街弑〆低调 提交于 2020-05-13 04:02:12
问题 I am migrating to the new dagger android 2.11 All set up based on the Google blueprint :MVP-Dagger.but I am having this error : Error:(22, 57) error: @Binds methods must have only one parameter whose type is assignable to the return type Here in this line : @ActivityScoped @Binds abstract PresenterFactory<MainContract.Presenter> providePresenterFactory(MainPresenter presenter); The presenter : @ActivityScoped public class MainPresenter extends BasePresenterImpl<MainContract.View> implements

@Binds methods must have only one parameter whose type is assignable to the return type

做~自己de王妃 提交于 2020-05-13 03:58:40
问题 I am migrating to the new dagger android 2.11 All set up based on the Google blueprint :MVP-Dagger.but I am having this error : Error:(22, 57) error: @Binds methods must have only one parameter whose type is assignable to the return type Here in this line : @ActivityScoped @Binds abstract PresenterFactory<MainContract.Presenter> providePresenterFactory(MainPresenter presenter); The presenter : @ActivityScoped public class MainPresenter extends BasePresenterImpl<MainContract.View> implements

android面试题(5.4)

我是研究僧i 提交于 2020-05-05 17:48:08
2020年Android面试题含答案 Android 2020年经典面试题 链接到 1.跨进程通信的几种方式 Intent,比如拨打电话 ContentProvider数据库存储数据 Broadcast广播通信 AIDL通信,通过接口共享数据 2.wait和 sleep 的区别 wait是Object的方法,wait是对象锁,锁定方法不让继续执行,当执行notify方法后就会继续执行,sleep 是Thread的方法,sleep 是使线程睡眠,让出cpu,结束后自动继续执行 3.String,StringBuffer,StringBuilder的区别 String不可改变对象,一旦创建就不能修改 String str="aaa"; str="bbb"; 以上代码虽然改变了str,但是执行过程是回收str,把值赋给一个新的str StringBuffer创建之后,可以去修改 StringBuilder也可修改,执行效率高于StringBuffer,不安全 当字符赋值少使用String 字符赋值频繁使用StringBuilder 当多个线程同步操作数据,使用StringBuffer 4.View和SurfaceView的区别 View基于主线程刷新UI,SurfaceView子线程又可以刷新UI 5.View的绘制原理 View为所有图形控件的基类,View的绘制由3个函数完成