Reputation: 393
I am creating an app which needs to retrieve a textfile from a webserver.
I have the manual retrieving done, just that I am thinking of adding a service to make the service check for the textfile like every 5 minutes and then send a notification to the user when a textfile is detected.
Is it ok to use a service here or do I have to use other methods?
Because the service will be kept running.
Upvotes: 2
Views: 177
Reputation: 8533
The best way of doing this is setting a repeating alarm using AlarmManager
, a PendingIntent
and a BroadcastReceiver
as well as a Service
. That way you don't have the service running all the time.
So the AlarmManager
fires off the PendingIntent
which is then picked up by the BroadcastReceiver
which then starts your Service
to perform the task in the background using a Thread
or AsyncTask
etc. Also look at IntentService
which runs a Looper
to process an Intent
and then shuts itself down.
Upvotes: 1
Reputation: 10479
This is a great use of a service. Just make sure to allow the user to enable or disable service component. Also, try to shut it down when its not necessary (when the user cannot react to it).
Upvotes: 0