android - 唤醒锁在 Nexus 5 上不断抛出异常

标签 android exception wakelock

我们最近得到了一台 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/

相关文章:

java - StringIndexOutOfBoundsException 字符串索引超出范围 : 0

android - 当屏幕在 Android 中被阻止时?

android - 将手势生成器添加到我的应用程序?

java - 如何以编程方式隐藏 android 一些但不是全部的 XML 输出中的查看项目?

android - 如何解决错误 : "Not sure how to handle insert method' s return type"in implement room with RX java

java - 什么时候抛出/捕获一般异常是可以接受的

android - 取消应用程序自动续订订阅android

exception - kotlin如何将检查异常更改为运行时异常?

android - 删除从库中合并的不需要的 WAKE_LOCK 权限

android - 唤醒屏幕并在锁定屏幕上显示对话框