as the title says, I'm trying to figure out which one is the best way to insert a dependency in a fragment. I want to be independent of external frameworks like RoboGuice etc.
Now, in the simplest way, I have an interface that abstracts some logic, and from Activity I want to implement an implementation of this interface. I know that I need to provide a default constructor for my fragment, because at some point the system may need to recreate the fragment, and the usual way to create a new instance of the fragment is to provide a static method that handles the creation like this:
public static Fragment newInstance() { final Bundle bundle = new Bundle(); ... final Fragment fragment = new MyFragment(); fragment.setArguments(bundle); return fragment; }
How to convey your dependence on a fragment? Should I implement a Parcelable or Serializable interface and then pack it in a bundle? Is there any other way to achieve the result?
Thanks!
android dependency-injection dependencies code-injection fragment
TheImplementer
source share