On Dec 18, 2:41 am, sukumar <[email protected]> wrote:
> hi,
>
> Thats not my doubt. My service needs to read some data using htttpget,
> this action is performed onStart method of the service. While service
> is in middle of reading data from web. If someone starts the service
> again. What happens to the task started first? Will the service ends
> the first task and starts again from onStart function or Will service
> run the two task in separate two threads?
>
> -Sukumar.

Creating a service does not create a new thread. This makes the
concept of Service almost seem pointless? I have had similar doubts
and I wondered what the point may be for the creation of background
processes. I ended up implementing a Service anyway, to conform with
the app model. From the overridden onStart() method, I create threads
that handle things as if they were created straight out of the main
app. This makes it easier to handle all those "dark" state changes.
Beware: You are blocking your main app thread if you call httpGet from
the onStart() method as you describe. If the handset cannot get
through to the web, the main thread is blocked, and you will get those
Kill-app/wait dialog boxes. I've isolated interactions with web
servers in a separate thread where I don't bother the main app and
bodge the user experience. This also allows me to manage threads just
as I normally would, e.g. blocking the creation of duplicates etc.
Now that's just what I came up with. Perhaps I understand something
wrong there, but it works and appears reasonably well architected.

--~--~---------~--~----~------------~-------~--~----~
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