简体   繁体   English

WakeLock会导致手机重启吗?

[英]Could WakeLock cause phone reboot?

I have an app need to continuously using WiFi and accelerometer sensor to collect data, so I need to use WakeLock method to keep these sensors active. 我有一个应用程序需要持续使用WiFi和加速度传感器来收集数据,因此我需要使用WakeLock方法来保持这些传感器处于活动状态。 But now I meet the problem that the phone sometimes randomly reboot after running several hours. 但是现在我遇到了一个问题,即手机在运行几个小时后有时会随机重启。 I don't know whether this causes by my app or the phone's firmware. 我不知道这是由我的应用还是手机的固件引起的。 Does anybody have some ideas about it. 有人对此有想法吗? Actually, only one thing I think special in my app is that I need to use WakeLock all the time, so could wakelock cause phone randomly reboot? 实际上,我认为应用程序中唯一一件特别的事情是我需要一直使用WakeLock ,所以唤醒锁定会导致电话随机重启吗?

WakeLock doesn't usually cause Reboot problems. WakeLock通常不会导致重新启动问题。 There may be some other issues in your coding. 您的编码中可能还有其他问题。 WakeLock hogs battery heavily, if not released after usage. WakeLock会消耗大量电池,如果使用后没有释放电池。

WakeLock is an Inefficient way of keeping the screen on. WakeLock是使屏幕保持打开状态的一种低效方式。 Instead use the WindowManager to do the magic. 而是使用WindowManager来做魔术。 The following one line will suffice the WakeLock. 下面的一行足以满足WakeLock的要求。 The WakeLock Permission is also needed for this to work. WakeLock权限也需要此项才能起作用。 Also this code is efficient than the wakeLock. 同样,此代码比wakeLock有效。

getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);

You need not relase the WakeLock Manually. 您无需手动释放WakeLock。 This code will allow the Android System to handle the Lock Automatically. 此代码将允许Android系统自动处理锁定。 When your application is in the Foreground then WakeLock is held and else android System releases the Lock automatically. 当您的应用程序位于前台时,将保持WakeLock,否则android系统会自动释放Lock。

You should try using android:keepScreenOn="true" in any of the layout where you need wakelocks. 您应该在需要唤醒锁的任何布局中尝试使用android:keepScreenOn =“ true”。 It handles it automatically, and it's probably better to set this just in your xml layouts as it does not clutter your code with display related code. 它会自动处理它,最好在xml布局中设置它,因为它不会与显示相关的代码使您的代码混乱。

It's being talked about in Google IO 2009. http://dl.google.com/io/2009/pres/W_0300_CodingforLife-BatteryLifeThatIs.pdf 正在Google IO 2009中进行讨论。http: //dl.google.com/io/2009/pres/W_0300_CodingforLife-BatteryLifeThatIs.pdf

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM