When reading Android's documentation on threads and processes. The documentation is too ambiguous they say that it runs under a single thread called main
but not sure whether it's single threaded per process or across processes.
I'm trying to understand the thread creation in my phone. I just created two sample apps and tried to print the current thread id
and thread name
using Thread.currentThread().getId()
and Thread.currentThread().getName
in both the apps the thread name was main
and the thread id
is 2
. Similarly I tried printing process id for individual app with android.os.Process.myPid()
- the process id
were different. So it's obvious that it's creating new process for each application.
I'm doubtful whether it's the same thread used for rendering the activity between Application1 and Application2. If yes, how this is handled by Android framework? If it's a single thread for the entire device (phone) then what happens when I invoke Thread.currentThread().sleep(1000 * 60 * 60)
in one application and try to launch another activity from Application2 from adb
shell command. Will this cause any exception here?
Is there any thread pool associated with a process - in the case of Android when it creates a new process for an Application?
As per my understanding, zygote
process is cloned during each application process is getting created (the parent process would be zygote)? Is zygote
creating a main thread which all the applications are reusing?
How does process and threads are associated with each other? Can parent and child process share the threads?