Will all threads be killed when a service stopped?

2019-05-16 18:17发布

问题:

In the onStartCommand() method of my service, I start a long-running thread.

The service is started in my MainActivity's onCreate().

When my application quit (the time Main Activity closed by user), I stop the service. But I want to ensure that the thread mentioned before has been killed, or I have to stop the thread before/after that.

So will all threads started in a service be killed automatically when the service stopped?

回答1:

I have just checked this by logging the thread's state in my service's onDestroy(). The thread remains alive after my service stopped.