Meaningless Drivel is fun!*
The moose likes Android and the fly likes Services Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Services Query" Watch "Services Query" New topic
Author

Services Query

Sangel Kapoor
Ranch Hand

Joined: Jan 12, 2013
Posts: 51

Dear Pals

I have the following queries related to the Service Class which are not very clear to me

1.
Services run by default within the same main thread as the component from which they are launched. As such, any CPU intensive tasks that need to be performed by the service should take place within a new thread, thereby avoiding affecting the performance of the calling application.
Query : If that is the case why at all we need Services as another new component. Why not starting threads from the Application
Component instead of launching a Service and creating threads there.

2. Query : If we start new threads from an Activity , what would happen to them if Activity from which they were launched or the Application from which they were launched gets Destroyed ?

Thanks and Warm Regards
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41137
    
  45
A Service is a very different beast than an Activity, with a completely different lifecycle. If the thread is supposed to have the lifecycle of the associated Activity, then yes - you can start it from an Activity.

As to#2, I think the thread gets terminated, but that should be easy to test, no?


Ping & DNS - my free Android networking tools app
 
 
subject: Services Query
 
Similar Threads
Ending a thread without ending the JVM
Starting custom threads in Websphere Servlet Container
JSF scalability and performance issues... please help... important
Wicket, the big door for Java developers
Passed 700,701 and 340 last Thursday