Re: [android-developers] Prevent multiple copies of an Android service
On Thu, Mar 1, 2012 at 11:51 PM, Alan Smith <gpsanimator@gmail.com> wrote:
> The doco for startService states "If this service is not already running, it
> will be instantiated and started (creating a process for it if needed); if
> it is running then it remains running." I'm finding that each call to
> startService appears to be starting a separate instance of the service, in
> that the work that the service is doing (in my test case, trivially writing
> to a new log file) is being done again for each call.
That does not mean that there are multiple instances of the service.
onStartCommand() will be called for each startService() call, so if
your work is there (or, say, in onHandleIntent() of an IntentService),
N calls to startService() will result in N runs through your work.
--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy
Warescription: Three Android Books, Plus Updates, One Low Price!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home