-
Notifications
You must be signed in to change notification settings - Fork 546
SpiceManager in Application #211
Comments
I usually using one MainActivity with many Fragment, so you can create a SpiceManager in MainActivity and share it with all Fragment. |
You can also use inheritance to make a spice manager accessible in all your The problem with an application based spicemanager is that application Nevertheless, If the application gets killed, it will also kill its binding Also, I must add that what is really beneath your question is "how to Stéphane 2013/11/6 rey5137 notifications@github.com
Stéphane NICOLAS, |
@stephanenicolas For performance sake, is it ok to start and stop a SpiceManager in almost every fragments? Or would you recommend to follow @rey5137's way? Thanks |
If you start the same service twice, only one instance will be started. I 2013/11/6 Mathieu Castets notifications@github.com
Stéphane NICOLAS, |
So, if I understand, using inheritance, I'd better add the |
I don't use static keyword generally speaking. It makes code hard to test No, just provide each activity a spiceManager and manage the life cycle in 2013/11/6 Mathieu Castets notifications@github.com
Stéphane NICOLAS, |
I don't want to build application around any library. In my application architecture I've got few layers and I need the top layer that would be responsible for threading and networking and database management, so my Fragment/Activity doesn't know what is providing the data. I didn't want to write it on my own since there are good libs like this. Basically what I have is Fragment that calls requestSomeData(), and then few layers later there is class that will receive that call, that has no idea about life cycle, and I want just to run it in separate thread and pass the result in UI thread to layer that would decide if it should update Fragment content. So maybe it would be good just to automatically close SpiceManager if there was no new task for example 60seconds? Closing it every time when request queue is empty might be not that efficient. Is RoboSpice good choice when I need to do some work in background thread check if there is netwrok if yes make network request and put result in db, else get data just from db, and return it to main thread? |
@novemberox , yes RS is definitely a good choice for the use case you mention in the end. Although I must warn you that the ormlite module is a bit difficult to handle and as it remained orphan for a long time now, you will be more on your own than with any other module. I definitely recommend you to use RS from within an context component like an Activity or a Fragment (or a service) more than the application. I don't think it's really a good idea to want to de-couple things as much as you want to. I mean, yes it would be great, but life cycle is really a big part of Android and you can't really circumvent it. We spent a lot of time tackling that whole issue in a correct way in RS and that's why the lib is so useful on Android. But I would be happy to hear about working alternatives. I close the thread now as I think it was all a "talk/chat/discussion" rather than an issue per say. And after a few weeks off, I need to clean the backlog/issue board. |
Hi,
I was wondering if it is possible to have common SpiceManager across all Activities, that would be accessible from Application class?
Answering my question would be: "yes, you can do that". But then how the SpiceService would be stopped? Any solutions/advises for that?
Best
Mikołaj
The text was updated successfully, but these errors were encountered: