dagger 2 - Dagger2 - should an activity component be a sub-component of other? -


i used @subcomponent case activities need use shared objects application component, or fragments components want use objects provided container activity.

now wondering if can make activity components subcomponent of activity component. example, taskdetailactivity has task object , want provide other activities such taskparticipantactivity, taskprogressactivity , fragments.

the traditional way provide task object other activities set intent object, how if want use dagger2 case?

update: sistuation similar case of userscope in article http://frogermcs.github.io/dependency-injection-with-dagger-2-custom-scopes/, instead of saving user component in application class, can save in activity, i.e taskdetailactivity?

components grouping objects of similar lifecycle. while components may happen correspond particular set of functionality (like taskcomponent injecting taskactivity , taskpresenter) not possible or desirable insist on 1 component per set of functionality (for instance, insisting on 1 taskcomponent task related activities , dependencies).

instead, in dagger 2 re-usability available through modules can swap in , out of components. within constraints of advice organising modules testability in dagger 2 official documentation able organise modules congruent functionality (e.g., taskmodule all-task related dependencies). then, because components lightweight, can make many deal different lifecycles of activities , on. remember can compose modules using class<?> [] includes() method inside module @interface.

in particular scenario, want share task object taskdetailactivity. if held reference task within taskdetailactivity reference no longer available when taskdetailactivity destroyed. while try solution of holding binding task in module , maintaining reference module @ app-scope level, doing same userscope @ app-scoped level in article have linked. kind of solution sharing task object between activity using dagger 2 involve maintaining reference object @ app-scoped level.

using dagger 2 doesn't mean new keyword or serialization/deserialization of parcelables wrong , if first intuition use intent communicate right. if need more robust solution directly communicating task, extract taskrepository , transmit intent between activity contains id of task wish retrieve. indeed, of google android architecture blueprints have solution this.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -