【发布时间】:2014-01-20 12:29:22
【问题描述】:
我们最近将 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" />
适用于 Google Cloud Messenger
我还确保在我们的应用中发生这种情况。按包名过滤 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);
}
}
【问题讨论】:
-
你有一些关于如何获取/使用锁的示例代码吗?
-
您是否在服务工作结束时通过
WakefulBroadcastReceiver正确清除锁定(例如,onHandleIntent())? -
我们从这里使用了一个几乎复制粘贴的 GcmIntentService 版本:developer.android.com/google/gcm/client.html,就像我们在最后调用 completeWakefulIntent(intent) 的 onHandleIntent(Intent intent) 方法一样。
-
我没有在我的应用程序上使用唤醒锁并且经常看到这个。我不认为这是您的应用,我认为这是 4.4 中的错误
标签: android exception wakelock