I have an application that updates the database every so often but as soon as I close the application or switch activities it stops updating. I assume that using a service class would help this problem but I do not know how have the service refresh my activity or just update the database. my question is how would I use a service to update my database? if it helps my database pulls in three strings into the database that is put in by the user.
Share
Yes, the best solution to make this continuously run is putting the task in a Service.
Now as for your view updates, what API level are you using? If you’re using 3.x+, it’ll be beneficial for you to look into Loaders since those will update your view immediately on database changes.
For all other API levels, one solution is to make the activities register as listeners to your service. Whenever the service completes a database update, send a message to all registered listeners of that service. However, when you’re doing this, you will have to make sure that you register the activity as a listener in onResume and unregister in onPause to avoid any null pointer situations.