通过是否发起活动线程继续运行,一旦设备进入睡眠状态?线程、睡眠、状态、继续

2023-09-08 09:02:02 作者:戒酒的李白.

这是有点类似App似乎停止工作时,屏幕进入休眠状态但他们讨论的AsyncTask的,而在我的情况下,它是一个普通的线程。

This is somewhat similar to App seems to stop working when the screen goes to sleep however they discuss an AsyncTask while in my situation it is a plain Thread.

所以我们说一个活动启动一个线程,然后手机进入睡眠状态,并线程继续执行?

So let's say an activity starts a Thread, and then the phone goes to sleep, does the thread continue execution?

推荐答案

除非你有一个的激活锁定。 (它不会继续,如果你的活动转到后台运行,但可能会在前台活动需要更多的资源任何时候被杀死。)

Not unless you have a wakelock. (It does continue to run if your activity goes to the background, but might be killed at any time the foreground activity requires more resources.)