Will all threads be killed when a service stopped?

2019-05-16 17:49发布

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条回答
趁早两清
2楼-- · 2019-05-16 18:19

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

查看更多
登录 后发表回答