【问题标题】:Wake lock continually throws an exception on Nexus 5唤醒锁在 Nexus 5 上不断抛出异常
【发布时间】: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


【解决方案1】:

这可能与我在使用 MediaPlayer 时遇到的问题相同。当我要求 MediaPlayer 在我的单独线程服务中为我处理唤醒锁时,我每隔五秒左右就会收到 Wake lock not active..

我发现这来自我刚刚从示例代码中复制的代码。如果我像示例中那样从 public IBinder onBind(Intent intent) 抛出 UnsupportedOperationException,我会每隔五秒左右得到上述异常 Wake lock not active。

简单的解决方案是返回 null 而不是抛出异常。

希望对你有所帮助。

【讨论】:

  • 嗯,我去看看这是否是我们案例中的来源
【解决方案2】:

我遇到了同样的错误,但由于过于频繁地调用 MediaPlayer.setVolume。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    • 1970-01-01
    • 2017-03-09
    相关资源
    最近更新 更多