Sujin Shrestha
Sujin Shrestha

Reputation: 1253

Why do we need @SubComponent in Dagger 2?

What is the use of @Subcomponent in our application?

  @Subcomponent
    interface PostActivitySubComponent : AndroidInjector<PostsActivity> {

        @Subcomponent.Builder
        abstract class Builder : AndroidInjector.Builder<PostsActivity>()
    }

The application works fine with and without this component. What is the purpose of this?

Upvotes: 0

Views: 119

Answers (1)

Saaanty
Saaanty

Reputation: 195

@SubComponent is very helpful for the large application where Activities/Fragments where you provide dependencies for the specefic screen. For example you have AppComponent and SubComponent named ProfileDetailedComponent and you have no posssibility to control memory , but SubComponent help to you control memory with @Scope. For the each screen you will create SubComponent and SubComponent annotated all provides with @CustomScope and when user leave current screen , you can clear current component and free up memory , in the onDestroy() method. In sum @SubComponent need to contol your application memory.

Upvotes: 1

Related Questions