Consider the scenario that I am calling Webservice at Presenter A and holding the response data at the same Presenter. I want to utilize the same response data at Presenter E. But I cant pass the response object to each presenter B, C, D. So, I tried to store my response object at separate Holder class with getter & setter. I initialized Holder class using Dagger Inject constructor annotation and tried to consume it at Presenter E . But I got Empty response instead of my datas . Can any one suggest me to handle this scenario in best way . Thanks in advance
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
You have a lot of fundamental problems with how you're using Dagger2, but my time is limited, so I'll answer for the time being regarding Mortar - all I can say is that on some devices,
getSystemService()
is called sooner inApplication
thanonCreate()
, which means you should initialize your root mortar scope like this:Personally, I had this in my
onCreate()
And in InjectorService:
As such, in the worst case scenario,
getSystemService()
initialized my RootScope either at start-up, or when the singleton dagger component was created.This solution is currently not multi-process friendly (so Firebase Crash Reporting would kill it by calling
onCreate()
inCustomApplication
twice)EDIT: Injector Service code
As for your initial question, it's because you added
@Inject
annotation to your constructor, but did not include@Singleton
on the class itselfEDIT:
I got home from vacation, so initial error is
It refers to this class in
App
:Which inherits from this class:
...which is totally NOT a module, so that annotation is unnecessary, but hey.
Anyways, the issue now is that while the dependency is scoped, it is from a different scope (I didn't know the singleton scope isn't used), so if you change
to
Then if in
ScreenA
you changeto
Then it says
I can imagine this solution to your problem.
The point is, you need to remove from your presenter the
ApiRequest
and use ainteractor
, the both presenter receives this Interactor injected in his constructor, in this case they will share the same interactor instance (if he was a singleton). The interactor is responsible for doing the cache, if you are usingOkHttpClient
you can make the cache without using aholder class
(up to you), in this solution you will not perform 2 api calls for the same data.Something like this: