dagger-2

Espresso Test Failed: Wanted to match 1 intents. Actually matched 0 intents

。_饼干妹妹 提交于 2020-02-21 13:09:56
问题 I am trying to test that my SplashActivity correctly launches HomeActivity if the user is logged in. I have looked at related questions on StackOverflow, this seems to be a common issue, but I just cannot seem to get anything to work. I have watched the test execute on my device and visually verified that SplashActivity is indeed launching HomeActivity. HomeActivity expects a plain intent with no data. Here is the full error: IntentMatcher: has component: has component with: class name: is

Espresso Test Failed: Wanted to match 1 intents. Actually matched 0 intents

孤街醉人 提交于 2020-02-21 13:08:35
问题 I am trying to test that my SplashActivity correctly launches HomeActivity if the user is logged in. I have looked at related questions on StackOverflow, this seems to be a common issue, but I just cannot seem to get anything to work. I have watched the test execute on my device and visually verified that SplashActivity is indeed launching HomeActivity. HomeActivity expects a plain intent with no data. Here is the full error: IntentMatcher: has component: has component with: class name: is

@Provides and @Binds methods in same class Kotlin

折月煮酒 提交于 2020-02-18 09:07:31
问题 After dagger 2.11 we can use a @Binds annotation and mark our Module as abstract in this case which is more efficient than a concrete. If my Module has both @Provides and @Binds methods, I have two options : Simplest would be to mark your @Provides instance methods as static. If it is necessary to keep them as instance methods, then you can split your module into two and extract out all the @Binds methods into an abstract Module. The second option works fine in Java and Kotlin but the first

injecting viewmodel with navigation-graph scope: NavController is not available before onCreate()

梦想的初衷 提交于 2020-02-15 00:22:42
问题 I'm using a navigation-component in my application and also using shared ViewModel between multiple fragments that are in the same graph. Now I want to instantiate the ViewModel with this graph scope with this. As you know, in fragments we should inject objects ( ViewModel,..etc ) in onAttach: but when I want to do this (injecting ViewModel with a graph scope in onAttach ), this error occurs: IllegalStateException: NavController is not available before onCreate() Do you how can I do this? 回答1

injecting viewmodel with navigation-graph scope: NavController is not available before onCreate()

此生再无相见时 提交于 2020-02-15 00:21:08
问题 I'm using a navigation-component in my application and also using shared ViewModel between multiple fragments that are in the same graph. Now I want to instantiate the ViewModel with this graph scope with this. As you know, in fragments we should inject objects ( ViewModel,..etc ) in onAttach: but when I want to do this (injecting ViewModel with a graph scope in onAttach ), this error occurs: IllegalStateException: NavController is not available before onCreate() Do you how can I do this? 回答1

injecting viewmodel with navigation-graph scope: NavController is not available before onCreate()

老子叫甜甜 提交于 2020-02-15 00:20:10
问题 I'm using a navigation-component in my application and also using shared ViewModel between multiple fragments that are in the same graph. Now I want to instantiate the ViewModel with this graph scope with this. As you know, in fragments we should inject objects ( ViewModel,..etc ) in onAttach: but when I want to do this (injecting ViewModel with a graph scope in onAttach ), this error occurs: IllegalStateException: NavController is not available before onCreate() Do you how can I do this? 回答1

Why Dagger inject is not working but component.getObject yes

泪湿孤枕 提交于 2020-02-08 02:32:51
问题 I am trying to use Dagger 2 for instantiating a Retrofit interface. The CloudContactDataStore class injects the RestClient and calls its methods. When I instantiate a CloudContactDataStore object, its RestClient attribute has null value. public class CloudContactDataStore implements ContactDataStore { @Inject RestClient restClient; public CloudContactDataStore() { this.initializeInjector(); } private void initializeInjector() { ApiComponent component = DaggerApiComponent.builder() .apiModule

cannot be provided without an @Provides-annotated method Dagger/MissingBinding

巧了我就是萌 提交于 2020-02-06 08:01:55
问题 Unable to inject presenter to Activity BookDashboard -> Activity class BookDashboard : AppCompatActivity(),BookDashboardContract.MvpView{ @Inject lateinit var presenter: BookDashboardContract.Presenter override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) presenter.fetchedBooks() // if I pass no parameter to BookPresenter than UninitializedPropertyAccessException: lateinit property presenter has not been initialized } override fun displayBooks() { Toast

@subcomponent.factory method is missing parameters for required modules or subcomponents

百般思念 提交于 2020-02-06 07:23:20
问题 I am injecting Presenter to BookDashboard (Activity) and BookDashboardPresenter class require an MvpView interface in it's constructor . When i run AppComponent @Component( modules = [ AndroidInjectionModule::class, ActivityBuilder::class ] ) @Singleton interface AppComponent : AndroidInjector<App> { @Component.Builder interface Builder { fun addContext(@BindsInstance context: Context): Builder fun addBookEngine(@BindsInstance bookEngineModule: BookEngineModule) :Builder fun build():

Dagger 2 Singleton Component Depend On Singleton

断了今生、忘了曾经 提交于 2020-02-01 00:13:31
问题 I've got a strange problem here, and I'm not quite sure why what I'm doing isn't allowed. I've got the following modules: @Module public final class AppModule { private Context mContext; @Provides @Singleton @AppContext public Context provideContext() { return mContext; } } @Module public final class NetModule { @Provides @Singleton public OkHttpClient provideOkHttp() { return new OkHttpClient.Builder().build(); } } For various reasons, I don't want to have these two modules in the same