views:

40

answers:

1

Hello everyone,

To be able to write "nice" code between my application/activies and a local service I need to understand some basic Android concepts:

What I'm wondering is if my application (as in my activities) and my local service is sharing one thread. I.e. when the activities and the local service executes tasks queued are these tasks interleaved in ONE thread thus sharing the thread or does the service has a thread of its own?

Also if the local service shares the thread with the activities and the local service makes a direct call (via a callback) to one of the activities (i.e. no post message) is the activity thread "halted" or is the execution of that specific function queued to be executed later anyway?

/ Henrik

+1  A: 

Via Application Fundamentals:

Like activities and the other components, services run in the main thread of the application process. So that they won't block other components or the user interface, they often spawn another thread for time-consuming tasks (like music playback). See Processes and Threads, later.

Now if the service is a separate application that is a different story..
also from Application Fundamentals:

In many ways, each Android application lives in its own world:

  • By default, every application runs in its own Linux process....
Quintin Robinson