The android.content.Context api exposes two methods for starting a
service. startService and bindService. The api docs state that when a
service is started with Context.startService, that requires the
service to remain running until stopService(Intent) is called,
regardless of whether any clients are connected to it.

I have made a test service that uses a postDelayed event. The Runnable
for the postDelayed increments++ a counter and writes that counter and
a timestamp to a text file every minute.

However, when the phone becomes inactive (screen times out) the
service seems to pause for a few hours, run a short while, then pause
for a few hours, then run a short while, and on and on...

Here is the log file. The service ran intermittently for 11 hours. I
can post the Service.java and Activity.java if requested. I am leaving
it out for berevity.

02/05/2009 10:27:07 PM: iCount = 1
02/05/2009 10:28:07 PM: iCount = 2
02/05/2009 10:29:07 PM: iCount = 3
02/05/2009 11:20:49 PM: iCount = 4
02/05/2009 11:31:11 PM: iCount = 5
02/05/2009 11:32:11 PM: iCount = 6
02/05/2009 11:33:16 PM: iCount = 7
02/05/2009 11:34:16 PM: iCount = 8
02/05/2009 11:35:16 PM: iCount = 9
02/05/2009 11:36:16 PM: iCount = 10
02/05/2009 11:37:16 PM: iCount = 11
02/05/2009 11:38:16 PM: iCount = 12
02/05/2009 11:39:16 PM: iCount = 13
02/05/2009 11:40:16 PM: iCount = 14
02/05/2009 11:41:16 PM: iCount = 15
02/05/2009 11:42:16 PM: iCount = 16
02/05/2009 11:43:17 PM: iCount = 17
02/05/2009 11:44:17 PM: iCount = 18
02/05/2009 11:45:17 PM: iCount = 19
02/05/2009 11:46:17 PM: iCount = 20
02/05/2009 11:47:17 PM: iCount = 21
02/05/2009 11:48:17 PM: iCount = 22
02/05/2009 11:55:58 PM: iCount = 23
02/06/2009 01:06:56 AM: iCount = 24
02/06/2009 03:07:41 AM: iCount = 25
02/06/2009 04:38:32 AM: iCount = 26
02/06/2009 06:54:49 AM: iCount = 27
02/06/2009 08:03:14 AM: iCount = 28
02/06/2009 08:57:50 AM: iCount = 29
02/06/2009 08:58:50 AM: iCount = 30
02/06/2009 08:59:50 AM: iCount = 31
02/06/2009 09:05:24 AM: iCount = 32
02/06/2009 09:06:24 AM: iCount = 33
02/06/2009 09:07:24 AM: iCount = 34
02/06/2009 09:08:24 AM: iCount = 35
02/06/2009 09:23:09 AM: iCount = 36
02/06/2009 09:23:17 AM: Service Destroyed.

My questions are:

1) Is this what is supposed to happen for an Android service?
2) If so, What should one do to get an application to run a specific
task at user-specified intervals in the background. Like retrieving
data from a web service...

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to