dagger

Android Dagger-2 how to provide the dependency for method parameters

江枫思渺然 提交于 2019-12-04 06:28:51
问题 I have a module FragmentModule @Module public class FragmentModule { @Provides public static PickerDashboardFragment providesPickerDashboard(int status, String name, Object someComplexObject) { PickerDashboardFragment fragment = new PickerDashboardFragment(); Bundle b = new Bundle(); b.putInt("status", status); b.putString("name", name); b.putInt("object", someComplexObject); fragment.setArguments(bundle); return fragment; } @Provides public static PickingFragment providesPickingFragment() {

Dagger 2 : How to bind Fragment Map in parent component from subcomponent for FragmentFactory

爷,独闯天下 提交于 2019-12-04 06:03:40
I have this Dagger 2 configuration: AppComponent.kt @Singleton @Component( modules = [ AndroidSupportInjectionModule::class, AppModule::class, ActivityBindingModule::class, ] ) interface AppComponent : AndroidInjector<AppApplication> { @Component.Builder abstract class Builder : AndroidInjector.Builder<AppApplication>() } ActivityBindingModule.kt @Module abstract class ActivityBindingModule { @ActivityScoped @ContributesAndroidInjector( modules = [ MainActivityModule::class, FragmentModule::class //a fragment factory for each activity ] ) internal abstract fun mainActivity(): MainActivity }

android完整资讯App、Kotlin新闻应用MVP + RxJava + Retrofit + Dagger2、优雅区间选择器等源码

佐手、 提交于 2019-12-04 05:58:18
Android精选源码 Android完整资讯客户端源码 android展示注册进度效果源码 Android Wifi热点数据传输Socket 通信示例源码 Android Dota的辅助信息app源码 Android 播报栏 一款Kotlin新闻客户端, MVP + RxJava + Retrofit + Dagger2 TODO 最适合练习主流框架的应用 (原创作者) BezierSeekBar优雅的区间选择器,贝塞尔曲线样式,丰富的自... Android优质博客 Android Activity四种启动模式图文详解 Activity是安卓上最聪明的设计之一,优秀的内存管理让多任务完美运行在最流行的操作系统之上。并不是让Activity在屏幕上启动就完事了,其启动方式也是需要关注的。这个话题的内容很多,其中很重要的就是启动模式(launchMode)。这也是我们这篇博客要讨论的内容。因为不同的Activity有不同的目的。有些被设计... 阅读原文 Android View绘制源码分析 Layout FrameLayout的位置是在父类View中就确定了的,不像measure流程大小是由子View的大小确定,自定义ViewGroup必须实现onLayout方法,因为在ViewGroup中该方法是个抽象方法,在layout执行完成后调用View的getWidth

Android Testing with Robolectric and Dagger

半腔热情 提交于 2019-12-04 05:49:14
问题 I am trying to write an Android application using Dagger. Trying to follow the TDD approach, I started writing a test for my First activity. For writing tests I am using Robolectric and I am trying to make it work in different scenarios using Mockito. Short story: I have an android activity which I want to test using robolectric. This activity has some of its dependencies provided through Dagger. I managed to make this work by overriding the Application class and providing a mock of the

Using Dagger2 with Lombok

倖福魔咒の 提交于 2019-12-04 04:28:29
Has anyone used Lombok 1.16 with Dagger2? My current code looks like: @AllArgsConstructor(onConstructor = @__(@Inject)) public class JuiceMaker { private final Apple apple; The error is: JuiceMaker cannot be provided without an @Inject constructor or from an @Provides-annotated method. Without the Lombok annotation this actually works, so: public class JuiceMaker { private final Apple apple; @Inject public JuiceMaker(Apple apple){ this.apple = apple } } works This is a copy paste version of my answer here : This is not a direct answer to the question, which seems to be solved, but acts as

Inject database in a ContentProvider with dagger

我的梦境 提交于 2019-12-04 02:33:16
I want to inject a singleton SqliteOpenHelper in a ContentProvider . However, it seems that the ContentProvider instance is being built before the Application instance is being created ( getApplicationContext() returns null). When can I inject the database? I've tried in the constructor and in the onCreate() method of the ContentProvider . I faced the same issue and had to defer injection until the database was needed. You might be able to use Dagger's lazy injection to achieve the same effect. From the content provider's onCreate documentation : You should defer nontrivial initialization

How to resolve a circular dependency while still using Dagger2?

好久不见. 提交于 2019-12-04 02:08:51
I have two classes, Foo<T> and Bar , which depend on each other, as well as various other classes. I am using Dagger-2 for dependency injection, but if I naively add the circular dependency, Dagger hits a stack overflow at runtime. What's a good way to refactor the classes to fix this, while still using Dagger to inject all the other dependencies, and with minimal duplication and changes to existing calls? The easy way out is to use Lazy<T> on one side. Lazy<Foo> foo; @Inject Bar(Lazy<Foo> foo) { this.foo = foo; } // use foo.get(); when needed After an excessive amount of thought and talks

Binding Into Map With KClass Type

只愿长相守 提交于 2019-12-03 15:04:06
问题 I am trying to bind subclasses of ViewModel into a map by their KClass types: @Module abstract class ViewModelModule { @Binds @IntoMap @ViewModelKey(MyViewModel::class) abstract fun bindsMyViewModel(viewModel: MyViewModel): ViewModel @Binds abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory } But I am getting Dagger compiler error: e: ~/Example/app/build/tmp/kapt3/stubs/debug/com/example/app/injection/AppComponent.java:5: error: [dagger.android

Dagger cannot create object graph although it can produce dot file

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 13:43:00
问题 I'm struggling with the setup of Dagger (1.0.1), in a existing application. It was configured to use ProGuard but I disabled it for this test with -dontobfuscate . When I enable dagger-compiler it's able to successfully generate a dot file with the dependencies graph, but when I remove the compiler and build the app in Release mode it crashes during startup, complaining that it's unable to create the object graph. java.lang.RuntimeException: Unable to start activity ComponentInfo{com.corp

Dagger 2 on Android: inject same dependency in Activity and retained Fragment

百般思念 提交于 2019-12-03 11:39:42
问题 I have objects of classes F1 and F2 that I want to inject in a retained Fragment. I also have an object of class A that depends on Activity, and I want it to be injected in that Activity and in a retained Fragment attached to that Activity's Fragment Manager. I write the following code. First, the module for the Activity dependency: @Module public class MainActivityModule { private Activity mActivity; public MainActivityModule(Activity activity) { mActivity = activity; } @Provides