Both the RestAdapter
and the generated instance of your services (MyTaskService
in this case) are extremely expensive objects and should be used as singletons.
This means that you should only ever call restAdapter.create
once and re-use the same instance of MyTaskService
every time you need to interact with.
I cannot stress this enough.
You can use the regular singleton pattern in order to ensure that there only is ever a single instance of these objects that you use everywhere. A dependency injection framework would also be something that could be used to manage these instances but would be a bit overkill if you are not already utilizing it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…