I wish to create a service which fetches remote data and updates the local db ready for the app running to interrogate.. I also wish to do the reverse at some point too, update the remote database with data from the local db. I want the service to run every 5 minutes, but also want the user to be able to trigger the service to run too..
Is this possible? Also can the service run without the app running? Ideally I would like the service to be independent from the app if possible which is always running? Am I asking too much
I do this in several apps so it is perfectly possible. Have a read of the service tutorial. One thing you need to be aware of is if you want a totally independent service then you will need to manage the service so it isn't running when the app is running. I manage this via intents but there are other ways of doing it.
I have read the tutorial and have downloaded the demo. Stuck in my db sync into the demo too and have it running as a service. That did seem a bit too straightforward to do of course but I guess actually implementing it will be the interesting bit .. I'm guessing if it is a total independent service it will be a different project completely to my app. I'll have to think about that but as long as the service runs even when the app is 'sleeping' that will do for me..
Service runs on the same thread with app, this mean some long operations on main app or some event in main app that halt the thread - like modal dialog, could / will halt service operations.
I think separating service app and main app could make service runs independently.
Usually you don't. My service is generic and has a configuration file so it can grab data from multiple REST endpoints and update multiple databases. This means I only need to run one service for multiple apps. Probably something most developers don't need to do.
It is not only about SQL. Sometime, data return from SQL need to combine with local data and recalculated again before presented to users.
If calculations is quite complex or data to process is big, it could delay the app.
If just a simple operation, no need to separate it.