Reputation: 21
I use a service to continuously synchronize information to display on the activity. The service runs an endless loop while(true) in which the information is updated every 10 seconds. In some devices the service stops after a time of execution. How I can keep the task of the intentService running? It must run even if the user minimize the application.
Upvotes: 0
Views: 498
Reputation: 10288
A Service
is ideal for hosting long-running processes that outlive any one activity. If you're just displaying the data, as opposed to saving it or doing some kind of background processing with it, there's no reason to use a Service
at all. Just use Handler#postDelayed(...)
in the activity, and make sure the task is removed on pause.
Polling every ten seconds is probably excessive. In fact, polling at all is probably inefficient, unless you expect the data to change as frequently as you are polling.
Upvotes: 0
Reputation: 1520
You shoudn't do that (and you even can't since android 6.0: doze). Consider using cloud messaging to notify your app that something has changed on the server.
Upvotes: 3