0

I just wanted to know that on which thread the service runs? I'hv heard that it run in the main thread of their hosting process. If this is true then why doesn't it blocks **UI**, and even if application exits the service continuous to run in background. Please help me in this. Again What am i asking is service runs on main thread then why doesn't it blocks UI(ANR) ? Answers will be appreciated. Thanks.

Shubham
  • 1,442
  • 3
  • 16
  • 34

2 Answers2

0

Try

Log.d("~~~","thread id="+Thread.currentThread().getId()+"  name="+Thread.currentThread().getName());

It prints the name and the numeric id of the thread.

PS Use android.os.Process.myPid() to get the process id.

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
  • I am not asking that i'm asking if it runs on main thread then why doesn't it blocks UI(Application Not Responding). – Shubham Jun 05 '14 at 06:51
0

If you carefully read the Android Documentation, you can find that : "Note that services, like other application objects, run in the main thread of their hosting process."

If you want your Service to run in a new Thread, you have to create that Thread yourself (or you may take a look at IntentService).

FatL
  • 171
  • 6