我们最近得到了一台 Nexus 5 作为测试设备。它正在运行 Android 4.4.2。问题是它每隔 2 到 4 秒就会不断发出以下异常作为警告:
01-02 22:33:33.482 751-894/? W/Binder﹕ Caught a RuntimeException from the binder stub implementation.
java.lang.IllegalArgumentException: Wake lock not active
at com.android.server.power.PowerManagerService.updateWakeLockWorkSourceInternal(PowerManagerService.java:794)
at com.android.server.power.PowerManagerService.updateWakeLockWorkSource(PowerManagerService.java:780)
at com.android.server.power.PowerManagerService.updateWakeLockUids(PowerManagerService.java:761)
at android.os.IPowerManager$Stub.onTransact(IPowerManager.java:103)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
我们测试过的其他手机均未显示相同的警告(包括运行 4.4.2 的 Nexus 4)
我们正在使用 WAKE_LOCK 权限
<uses-permission android:name="android.permission.WAKE_LOCK" />
谷歌云信使
我还确保在我们的应用程序中发生这种情况。按包名称过滤 logcat 后警告仍然存在。它也会在您退出应用程序后立即停止。
这导致的主要问题是 Android Studio 在一段时间后滞后,所以我需要清除 logcat。此外,运行时异常也不是我想要撒谎的东西。知道为什么会这样吗?
[编辑]
这是我们代码中使用它的地方。它只是来自 Google 的 GcmBroadcastReceiver
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver
{
public void onReceive(Context context, Intent intent)
{
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
setResultCode(Activity.RESULT_OK);
}
}
最佳答案
这可能与我在使用 MediaPlayer 时遇到的问题相同。当我要求 MediaPlayer 在我的单独线程服务中为我处理唤醒锁时,我每五秒左右就会得到唤醒锁未激活..
我发现这来 self 刚刚从示例代码中复制的代码。如果我像示例中那样从 public IBinder onBind(Intent intent) 抛出 UnsupportedOperationException,我会每隔五秒左右收到上述异常 Wake lock not active。
简单的解决方案是返回 null 而不是抛出异常。
希望对你有帮助。
关于android - 唤醒锁在 Nexus 5 上不断抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20893442/