[英]onResume in android Service
In my application I have a Service
that creates some Thread
s. 在我的应用我有一个Service
,创造一些Thread
秒。 When the device goes in sleep mode, the threads are interrupted and destroyed. 当设备进入睡眠模式时,线程将被中断并销毁。 Assuming that I cannot use my Activity
's onResume()
(because I am using StandOut
library and StandOutWindow
extends Service
), how can I recreate/restart the Thread
s when I wake up my device? 假设我无法使用Activity
的onResume()
(因为我使用的是StandOut
库,而StandOutWindow
扩展了Service
),那么当我唤醒设备时如何重新创建/重启Thread
?
Would be catching screen on/off Intent
sa good idea? 可以打开/关闭屏幕Intent
是个好主意吗?
System suspend should not destroy your thread, it just put your thread suspend. 系统挂起不应破坏您的线程,它只会使您的线程挂起。 Your thread should not be always running, if it need to finish its job, grasp a weak lock. 您的线程不应该一直运行,如果需要完成工作,请抓住弱锁。
You can register a runtime broadcast receiver to watch screen on/off state to handle it. 您可以注册运行时广播接收器以观看屏幕的打开/关闭状态以进行处理。 It is a normal approach. 这是正常的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.