无法初始化显示事件接收器

32

我做了一个应用程序,定期启动一个服务从服务器检索信息。

我使用AlarmManager来安排这个服务。这个操作很好地运行,并且应用程序每30分钟接收到闹钟。

应用程序正常工作,但在完全不活动的一整夜之后 - 我启动应用程序时,它会崩溃并显示错误:“无法初始化显示事件接收器”。

除此之外,一切都完美。

我搜索了很长时间,发现有其他人遇到过同样的问题,但还没有解决方案。

Process: it.unipi.iet.portolan.traceroute, PID: 13092
java.lang.RuntimeException: Failed to initialize display event receiver.  status=-2147483648
at android.view.DisplayEventReceiver.nativeInit(Native Method)
at android.view.DisplayEventReceiver.<init>(DisplayEventReceiver.java:61)
at android.view.Choreographer$FrameDisplayEventReceiver.<init>(Choreographer.java:695)
at android.view.Choreographer.<init>(Choreographer.java:169)
at android.view.Choreographer.<init>(Choreographer.java:72)
at android.view.Choreographer$1.initialValue(Choreographer.java:98)
at android.view.Choreographer$1.initialValue(Choreographer.java:91)
at java.lang.ThreadLocal$Values.getAfterMiss(ThreadLocal.java:430)
at java.lang.ThreadLocal.get(ThreadLocal.java:65)
at android.view.Choreographer.getInstance(Choreographer.java:194)
at android.view.ViewRootImpl.<init>(ViewRootImpl.java:370)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:248)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2871)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2271)
at android.app.ActivityThread.access$800(ActivityThread.java:145)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1206)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5141)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:611)
at dalvik.system.NativeStart.main(Native Method)

一个问题:在您的服务中,您是否引用了正确的上下文? - Alessandro Verona
请在您遇到错误的地方添加代码。 - barq
1
然后提供一个最小的设置来重现这个问题。 - barq
请展示导致错误的相关代码。 - james
@Adri请展示最简代码。 - Reaz Murshed
显示剩余2条评论
1个回答

2

Just for some info

这里有一些信息,我不明白为什么, 报错信息来源于:

frameworks/base/core/jni/android_view_DisplayEventReceiver.cpp:4239:        message.appendFormat("Failed to initialize display event receiver.  status=%d", status);

也许是这个。
frameworks/base/libs/androidfw/DisplayEventDispatcher.cpp:1427:        ALOGW("Failed to initialize display event receiver, status=%d", result);

这是从DisplayEventReceiver返回的状态-2147483648 = 0x800000000

  /* initCheck returns the state of DisplayEventReceiver after construction.*/

status_t initCheck() const;

请查看DisplayEventReceiver.cpp文件。

status_t DisplayEventReceiver::initCheck() const {
if (mDataChannel != NULL)
    return NO_ERROR;
return NO_INIT;
}

看起来 mDataChannel 是空的, 构造函数中初始化了 mDataChannel。
DisplayEventReceiver::DisplayEventReceiver() {
    sp<ISurfaceComposer> sf(ComposerService::getComposerService());
    if (sf != NULL) {
        mEventConnection = sf->createDisplayEventConnection();
        if (mEventConnection != NULL) {
            mDataChannel = mEventConnection->getDataChannel();
        }
    }
}

如果 sf SurfaceComposer 为空或者 sf-> createDisplayEventConnection 返回为空。

并且在文件 ./system/core/include/utils/Errors.h 中。

...
NO_ERROR            =0
UNKNOWN_ERROR       = (-2147483647-1), // INT32_MIN value

NO_MEMORY           = -ENOMEM,
INVALID_OPERATION   = -ENOSYS,
BAD_VALUE           = -EINVAL,
BAD_TYPE            = (UNKNOWN_ERROR + 1),
NO_INIT             = -ENODEV,
...

看起来状态必须是NO_INIT...


https://android.googlesource.com/platform/frameworks/base/+/master/libs/androidfw/DisplayEventDispatcher.cpp - Yu Jiaao
感谢您的所有努力! - cV2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接