I have an app need to continuously using WiFi and accelerometer sensor to collect data, so I need to use WakeLock method to ke开发者_运维百科ep these sensors active. 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 doesn't usually cause Reboot problems. There may be some other issues in your coding. WakeLock hogs battery heavily, if not released after usage.
WakeLock is an Inefficient way of keeping the screen on. Instead use the WindowManager to do the magic. The following one line will suffice the WakeLock. The WakeLock Permission is also needed for this to work. Also this code is efficient than the wakeLock.
getWindow().addFlags(LayoutParams.FLAG_KEEP_SCREEN_ON);
You need not relase the WakeLock Manually. This code will allow the Android System to handle the Lock Automatically. When your application is in the Foreground then WakeLock is held and else android System releases the Lock automatically.
You should try using android:keepScreenOn="true" in any of the layout where you need wakelocks. 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.
It's being talked about in Google IO 2009. http://dl.google.com/io/2009/pres/W_0300_CodingforLife-BatteryLifeThatIs.pdf
精彩评论