dagger-2

MVP, set the view of the presenter to null on destroy?

不羁的心 提交于 2020-01-13 01:32:03
问题 I am currently trying to implement the MVP pattern on Android. However, I came to think about memory leaks (since the presenter holds a reference to the activity - the view). My question is, should I set the view of the presenter to null say onDestroy of the activity? This is my main activity: public class MainActivity extends AppCompatActivity implements MainView { private Button loadUser; private TextView mTextView; @Inject IMainPresenter mPresenter; @Override protected void onCreate(Bundle

MVP, set the view of the presenter to null on destroy?

岁酱吖の 提交于 2020-01-13 01:30:07
问题 I am currently trying to implement the MVP pattern on Android. However, I came to think about memory leaks (since the presenter holds a reference to the activity - the view). My question is, should I set the view of the presenter to null say onDestroy of the activity? This is my main activity: public class MainActivity extends AppCompatActivity implements MainView { private Button loadUser; private TextView mTextView; @Inject IMainPresenter mPresenter; @Override protected void onCreate(Bundle

Dagger v2: Inject 2 different scopes into one object

北城余情 提交于 2020-01-12 14:12:50
问题 I have moduleA setup as an application wide singleton provider, ModuleB as a user related object provider My user display fragment will use system wide bus to send message to others and use user related object to display. Problem cannot inject different scrope class into one object. Use component.getX method works fine, but inject is prefered way. Error message: @UserScope may not reference bindings with difference scopes: @Provides @Singleton Bus ModuleA.provideBus() @Module public class

Kotlin dagger 2 Android ViewModel injection error

穿精又带淫゛_ 提交于 2020-01-12 10:12:02
问题 I'm trying to use dagger 2 on my Android application to inject the new ViewModel from arch android library. From what I see on this sample https://github.com/googlesamples/android-architecture-components/tree/e33782ba54ebe87f7e21e03542230695bc893818/GithubBrowserSample I need to use this: @MustBeDocumented @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) @Retention(AnnotationRetention.RUNTIME) @MapKey internal

Kotlin dagger 2 Android ViewModel injection error

余生颓废 提交于 2020-01-12 10:10:31
问题 I'm trying to use dagger 2 on my Android application to inject the new ViewModel from arch android library. From what I see on this sample https://github.com/googlesamples/android-architecture-components/tree/e33782ba54ebe87f7e21e03542230695bc893818/GithubBrowserSample I need to use this: @MustBeDocumented @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER) @Retention(AnnotationRetention.RUNTIME) @MapKey internal

View dependency injection with dagger 2

会有一股神秘感。 提交于 2020-01-12 07:49:21
问题 I have a custom view extending a TextView . Where should I call my component to inject the view? component.inject(customTextView); 回答1: So, I've find out that I need to add the injection in the constructor of my custom view (in all of them, or make one call the other) Example: public class CustomTextView extends TextView { @Inject AnyProvider anyProvider; public CustomTextView(Context context) { this(context, null); } public CustomTextView(Context AttributeSet attrs) { super(context, attrs);

View dependency injection with dagger 2

主宰稳场 提交于 2020-01-12 07:49:12
问题 I have a custom view extending a TextView . Where should I call my component to inject the view? component.inject(customTextView); 回答1: So, I've find out that I need to add the injection in the constructor of my custom view (in all of them, or make one call the other) Example: public class CustomTextView extends TextView { @Inject AnyProvider anyProvider; public CustomTextView(Context context) { this(context, null); } public CustomTextView(Context AttributeSet attrs) { super(context, attrs);

Dagger 2, sometimes on compiling I get “cannot find symbol class DaggerApplicationComponent”

被刻印的时光 ゝ 提交于 2020-01-11 17:14:12
问题 Recent after update Android Studio (2.0.7) (maybe this is the cause) sometimes when building i get that error. Idea is that usually compilation goes well but sometimes I get dagger error. Is possible that is problem in Dagger configuration? Error itself: Executing tasks: [:app:assembleDebug] Configuration on demand is an incubating feature. Incremental java compilation is an incubating feature. :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild

Dagger 2, sometimes on compiling I get “cannot find symbol class DaggerApplicationComponent”

末鹿安然 提交于 2020-01-11 17:12:07
问题 Recent after update Android Studio (2.0.7) (maybe this is the cause) sometimes when building i get that error. Idea is that usually compilation goes well but sometimes I get dagger error. Is possible that is problem in Dagger configuration? Error itself: Executing tasks: [:app:assembleDebug] Configuration on demand is an incubating feature. Incremental java compilation is an incubating feature. :app:preBuild UP-TO-DATE :app:preDebugBuild UP-TO-DATE :app:checkDebugManifest :app:preReleaseBuild

How to Instantiate an object with dynamic members with Dagger2?

不羁岁月 提交于 2020-01-11 12:07:10
问题 I have a class which gets arguments in a constructor: public class Dependency{ Dependency(int number1, int number2, int number3, DependencyListener listener){} } each dependent class needs to path different arguments in order to instantiate a dependency. How should i define the module and the component that other classes could initiate it properly while transferring different values and passing 'this' as the listener? Also, How should i use the @Inject method in this case? Edit 1 @jeff-bowman