Inject application context reference to any where automatically. You can also inject the reference as you wish manually.
-
add following line in your project build.gradle file
dependencies { annotationProcessor "com.github.TangKe:ContextInjectorCompiler:latest.version" annotationProcessor "com.google.auto.service:auto-service:1.0-rc7" implementation "com.github.TangKe:ContextInjector:latest.version" }
-
add annotation
@InjectContext
to fields or method where you want, then invoke theContextInjector.inject(Object)
method (method must have only one parameter withContext
type, if your injected elements were modified bystatic
, the library will assign value or invoke method automatically when the Application been created, you don't need to invokeContextInjector.inejct(Object)
method) -
just enjoy
If your application contains more than one process, you should invoke
ContextInject.installMultiProcess(Application application)
in yourApplication.onCreate()
method