4

我们使用 NFC 标签作为进出停车票。在每个入口处,标签上都写有一些数据,并且在出口处,数据会验证车辆的出口。

部分车辆进出后,NfcService失效,智能手机无法检测到NFC标签。设备需要重新启动才能重新启动 NfcService,并且设备再次开始正常工作。

这个错误是随机出现的,我们一直无法在开发环境中重现这个错误,但是我们在安装在停车场出入口的设备上已经多次观察到这个问题。

当我们调试这个问题时,我们能够以某种方式管理上述日志。

我们尝试了不同的更改,例如使用enableReaderMode而不是enableForegroundDispatch,但问题仍然存在。

public void enableReaderMode() {
    try {
    Log.d("WTF", "Enabling reader mode");
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);

    if (nfc != null) {
        int flags = NfcAdapter.FLAG_READER_NFC_A ;

            nfc.enableReaderMode(this, new NfcAdapter.ReaderCallback() {
                @Override
                public void onTagDiscovered(Tag tag) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.d("WTF", "Tag discovered");
                            String uid = ByteArrayToHexString(tag.getId());
                            Toast.makeText(MainActivity.this, getString(R.string.message_tag_detected), Toast.LENGTH_SHORT).show();
                            Ndef ndef = Ndef.get(tag);

                            if (isNFCDialogDisplayed) {

                                if (isWrite) {

                                    mNfcWriteFragment = (NFCWriteFragment) getFragmentManager().findFragmentByTag(NFCWriteFragment.TAG);
                                    mNfcWriteFragment.onNfcDetected(ndef, uid);

                                } else {

                                    mNfcReadFragment = (NFCReadFragment) getFragmentManager().findFragmentByTag(NFCReadFragment.TAG);
                                    mNfcReadFragment.onNfcDetected(ndef, uid);
                                }
                            }
                        }
                    });

                }
            }, flags, null);

    }

    }catch (Exception e){
        Crashlytics.logException(e);
    }
}

public void disableReaderMode() {
    try {
    Log.d("WTF", "Disabling reader mode");
    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
    if (nfc != null) {
            nfc.disableReaderMode(this);
    }
    }catch (Exception e){
        Crashlytics.logException(e);
    }
}

NFCWriteFragment 和 NFCReadFragment 在内部读取和写入 NDEF 数据到标签。

StackOverflow 上的类似问题:

更新

将代码从 onResume 转移,因此活动在调用时始终处于活动状态enableReadeMode()且可见disableReaderMode()

这是新的日志

04-15 01:51:50.328 4987-4987/in.parksmart.operator D/WindowClient: 添加到 mViews: com.android.internal.policy.PhoneWindow$DecorView{55c53ae VE..... R.....我。0,0-0,0},这 = android.view.WindowManagerGlobal@ff3d558
04-15 01:51:50.329 4987-5037/in.parksmart.operator D/OpenGLRenderer: CanvasContext() 0x9cafb800
04-15 01:51:50.330 4987-4987/in.parksmart.operator D/ViewRootImpl:启用硬件加速,这 = ViewRoot{7de1f47 in.parksmart.operator/in.parksmart.operator.MainActivity,ident = 133}
04-15 01:51:50.354 4987-4987/in.parksmart.operator D/Surface: Surface::allocateBuffers(this=0x9de38200)
04-15 01:51:50.360 4987-5037/in.parksmart.operator D/OpenGLRenderer: CanvasContext() 0x9cafb800 初始化窗口=0x9de38208,标题=in.parksmart.operator/in.parksmart.operator.MainActivity
04-15 01:51:50.360 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1)
04-15 01:51:50.361 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1
04-15 01:51:50.361 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4)
04-15 01:51:50.366 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:51.181 4987-4999/in.parksmart.operator D/WTF:禁用阅读器模式
04-15 01:51:51.182 4987-4999/in.parksmart.operator D/WTF:NFC:不兼容标签
04-15 01:51:51.218 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:51:51.218 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:51.220 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:51:51.220 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1)
04-15 01:51:51.221 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1
04-15 01:51:51.221 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4)
04-15 01:51:51.224 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:51:51.432 4987-5077/in.parksmart.operator D/NativeCrypto: ssl=0xaa571900 sslWrite buf=0x9da11aa0 len=7 write_timeout_millis=0
04-15 01:51:51.432 4987-5077/in.parksmart.operator D/NativeCrypto:sslNotify,appData=0xaf928a00 ret=1
04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto: sslSelect, appData=0xaf928a00 被令牌唤醒
04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto:sslSelect,appData=0xaf928a00 读取 ret=1
04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto: sslSelect, appData=0xaf928a00 被令牌唤醒
04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto:sslSelect,appData=0xaf928a00 读取 ret=1
04-15 01:51:54.335 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d9715a0)(w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:51:54.414 4987-4987/in.parksmart.operator D/SettingsInterface:来自设置缓存,名称 = sound_effects_enabled ,值 = 0
04-15 01:51:54.414 4987-4987/in.parksmart.operator D/WTF:启用阅读器模式
04-15 01:51:54.467 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:51:54.467 4987-5037/in.parksmart.operator D/GraphicBuffer: 注销,句柄 (0x9c9cd8e0) (w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:51:54.468 4987-5037/in.parksmart.operator D/GraphicBuffer: 注销,句柄 (0x9d9715a0) (w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:51:54.471 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:51:54.471 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1)
04-15 01:51:54.472 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1
04-15 01:51:54.474 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4)
04-15 01:51:54.478 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d9715a0)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:54.485 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:54.506 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d971610)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:54.542 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d971680)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:54.976 4987-5000/in.parksmart.operator D/WTF:禁用阅读器模式
04-15 01:51:54.977 4987-5000/in.parksmart.operator D/WTF:NFC:不兼容的标签
04-15 01:51:55.003 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:51:55.003 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9d9715a0)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:55.004 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:55.005 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9d971610)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:55.005 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,处理(0x9d971680)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:51:55.007 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:51:55.008 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1)
04-15 01:51:55.009 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1
04-15 01:51:55.010 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4)
04-15 01:51:55.012 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d971680)(w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:51:56.966 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d971610)(w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:51:57.023 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:51:57.118 4987-4987/in.parksmart.operator D/SettingsInterface:来自设置缓存,名称 = sound_effects_enabled ,值 = 0
04-15 01:51:57.119 4987-4987/in.parksmart.operator D/WTF:启用阅读器模式
04-15 01:52:05.451 4987-4987/in.parksmart.operator E/NFC: NFC 服务失效 - 试图恢复
    android.os.DeadObjectException
        在 android.os.BinderProxy.transactNative(本机方法)
        在 android.os.BinderProxy.transact(Binder.java:511)
        在 android.nfc.INfcAdapter$Stub$Proxy.setReaderMode(INfcAdapter.java:614)
        在 android.nfc.NfcActivityManager.setReaderMode(NfcActivityManager.java:241)
        在 android.nfc.NfcActivityManager.enableReaderMode(NfcActivityManager.java:217)
        在 android.nfc.NfcAdapter.enableReaderMode(NfcAdapter.java:1299)
        在 in.parksmart.operator.NFCReadFragment.enableReaderMode(NFCReadFragment.java:131)
        在 in.parksmart.operator.NFCReadFragment$1.onClick(NFCReadFragment.java:100)
        在 android.view.View.performClick(View.java:5265)
        在 android.view.View$PerformClick.run(View.java:21534)
        在 android.os.Handler.handleCallback(Handler.java:815)
        在 android.os.Handler.dispatchMessage(Handler.java:104)
        在 android.os.Looper.loop(Looper.java:207)
        在 android.app.ActivityThread.main(ActivityThread.java:5728)
        在 java.lang.reflect.Method.invoke(本机方法)
        在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
04-15 01:52:05.452 4987-4987/in.parksmart.operator E/NFC:在服务恢复期间无法检索 NFC 服务
04-15 01:52:05.454 4987-4987/in.parksmart.operator I/Choreographer:跳过了 432 帧!应用程序可能在其主线程上做了太多工作。
04-15 01:52:05.473 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:52:05.473 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9d971680)(w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:52:05.474 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9d971610)(w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:52:05.475 4987-5037/in.parksmart.operator D/GraphicBuffer: 注销,句柄 (0x9c9cd8e0) (w:584 h:593 s:592 f:0x1 u:0x000f02)
04-15 01:52:05.477 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:52:05.478 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1)
04-15 01:52:05.480 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1
04-15 01:52:05.481 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4)
04-15 01:52:05.485 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:52:05.509 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:52:05.509 4987-5037/in.parksmart.operator D/GraphicBuffer:注销,句柄(0x9c9cd8e0)(w:656 h:497 s:656 f:0x1 u:0x000f02)
04-15 01:52:05.511 4987-5037/in.parksmart.operator D/Surface: Surface::disconnect(this=0x9de38200,api=1)
04-15 01:52:05.516 4987-4987/in.parksmart.operator D/WindowClient:从 mViews 中删除:com.android.internal.policy.PhoneWindow$DecorView{55c53ae VE.....R..... .D 0,0-528,369},这 = android.view.WindowManagerGlobal@ff3d558
04-15 01:52:05.516 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
04-15 01:52:05.517 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0 ]=-33.087376, y[0]=95.55115, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=6, eventTime=1689826, downTime=1689716 , deviceId=2, 源=0x1002 }
04-15 01:52:05.517 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
04-15 01:52:05.518 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0 ]=-33.087376, y[0]=95.55115, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1689842, downTime=1689716 , deviceId=2, 源=0x1002 }
04-15 01:52:05.518 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
04-15 01:52:05.519 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0 ]=353.3759, y[0]=527.21387, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1692129, downTime=1692129,设备 ID=2,来源=0x1002 }
04-15 01:52:05.520 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
04-15 01:52:05.520 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0 ]=353.3759, y[0]=527.21387, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=6, eventTime=1692243, downTime=1692129,设备 ID=2,来源=0x1002 }
04-15 01:52:05.520 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
04-15 01:52:05.521 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0 ]=353.3759, y[0]=527.21387, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1692258, downTime=1692129,设备 ID=2,来源=0x1002 }
04-15 01:52:05.521 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
04-15 01:52:05.521 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0 ]=393.3204, y[0]=526.21466, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1692338, downTime=1692338,设备 ID=2,来源=0x1002 }
04-15 01:52:05.521 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
04-15 01:52:05.522 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent { action=ACTION_MOVE, actionButton=0, id[0]=0, x[0 ]=393.3204, y[0]=526.21466, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=4, eventTime=1692416, downTime=1692338,设备 ID=2,来源=0x1002 }
04-15 01:52:05.522 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
04-15 01:52:05.522 4987-4987/in.parksmart.operator W/ViewRootImpl:由于根视图被删除而丢弃事件:MotionEvent { action=ACTION_UP, actionButton=0, id[0]=0, x[0 ]=393.3204, y[0]=526.21466, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=1692432, downTime=1692338,设备 ID=2,来源=0x1002 }
04-15 01:52:05.522 4987-4987/in.parksmart.operator W/InputEventReceiver:尝试完成输入事件,但输入事件接收器已被释放。
04-15 01:52:06.898 4987-4987/in.parksmart.operator D/SettingsInterface:来自设置缓存,名称 = sound_effects_enabled ,值 = 0
04-15 01:52:06.899 4987-4987/in.parksmart.operator E/NFC: NFC 服务失效 - 试图恢复
    android.os.DeadObjectException
        在 android.os.BinderProxy.transactNative(本机方法)
        在 android.os.BinderProxy.transact(Binder.java:511)
        在 android.nfc.INfcAdapter$Stub$Proxy.getState(INfcAdapter.java:365)
        在 android.nfc.NfcAdapter.isEnabled(NfcAdapter.java:642)
        在 in.parksmart.operator.MainActivity$PlaceholderFragment.lambda$onCreateView$4(MainActivity.java:2925)
        在 in.parksmart.operator.-$$Lambda$MainActivity$PlaceholderFragment$rsZBvNO0FFN0PjGCm8QiSvrhIqw.onClick(lambda)
        在 android.view.View.performClick(View.java:5265)
        在 android.view.View$PerformClick.run(View.java:21534)
        在 android.os.Handler.handleCallback(Handler.java:815)
        在 android.os.Handler.dispatchMessage(Handler.java:104)
        在 android.os.Looper.loop(Looper.java:207)
        在 android.app.ActivityThread.main(ActivityThread.java:5728)
        在 java.lang.reflect.Method.invoke(本机方法)
        在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
        在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
04-15 01:52:06.941 4987-4987/in.parksmart.operator D/WindowClient: 添加到 mViews: com.android.internal.policy.PhoneWindow$DecorView{dcd6d0c VE..... R.....我。0,0-0,0},这 = android.view.WindowManagerGlobal@ff3d558
04-15 01:52:06.942 4987-5037/in.parksmart.operator D/OpenGLRenderer: CanvasContext() 0x9f734800
04-15 01:52:06.943 4987-4987/in.parksmart.operator D/ViewRootImpl:启用硬件加速,这 = ViewRoot{5eeb4b3 in.parksmart.operator/in.parksmart.operator.MainActivity,ident = 134}
04-15 01:52:06.972 4987-5037/in.parksmart.operator D/OpenGLRenderer: CanvasContext() 0x9f734800 初始化窗口=0x9de38208,标题=in.parksmart.operator/in.parksmart.operator.MainActivity
04-15 01:52:06.972 4987-4987/in.parksmart.operator D/Surface: Surface::allocateBuffers(this=0x9de38200)
04-15 01:52:06.972 4987-5037/in.parksmart.operator D/Surface: Surface::connect(this=0x9de38200,api=1)
04-15 01:52:06.975 4987-5037/in.parksmart.operator W/libEGL:[ANDROID_RECORDABLE] 格式:1
04-15 01:52:06.976 4987-5037/in.parksmart.operator D/Surface: Surface::setBufferCount(this=0x9de38200,bufferCount=4)
04-15 01:52:06.980 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9c9cd8e0)(w:812 h:400 s:816 f:0x1 u:0x000f02)
04-15 01:52:07.008 4987-5037/in.parksmart.operator D/OpenGLRenderer: CacheTexture 4 上传: x, y, width height = 0, 0, 1024, 512
04-15 01:52:07.025 4987-5037/in.parksmart.operator D/GraphicBuffer:寄存器,句柄(0x9d974780)(w:812 h:400 s:816 f:0x1 u:0x000f02)
04-15 01:52:13.710 4987-5052/in.parksmart.operator D/NativeCrypto: ssl=0xaa571900 sslRead buf=0xaf907641 len=1,timeo=0
04-15 01:52:13.710 4987-5052/in.parksmart.operator D/NativeCrypto: ssl=0xaa571900 sslRead buf=0xaf917800 len=91,timeo=0
04-15 01:52:13.711 4987-5052/in.parksmart.operator D/NativeCrypto: ssl=0xaa571900 sslRead buf=0xaf907640 len=1,timeo=0
04-15 01:52:13.722 4987-4987/in.parksmart.operator D/FBDB: 孩子被移除
04-15 01:52:13.729 4987-4987/in.parksmart.operator D/FBDB:儿童被移除
04-15 01:52:13.729 4987-4987/in.parksmart.operator D/FBDB:孩子被移除

现在似乎不是活动娱乐的情况。每次我们希望连接 NFC 标签时enableReaderMode,我们都会打电话disableReaderMode,一旦标签的工作结束,我们就会打电话。

客户端使用的设备是天波900B。

4

2 回答 2

1

错误E/NFC: NFC service dead - 尝试恢复通常发生在标签和 Android 设备之间的连接性较差时(即当通信中断并且 NFC 服务无法从错误中恢复时)。在那些(罕见的?)情况下,NFC 服务会崩溃并尝试重新启动。

在某些情况下,您可以通过重新注册前台调度/阅读器模式来从应用程序内恢复该错误,例如使用

NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
if (nfc != null) {
    try { nfc.isEnabled(); } catch (Exception ignore) {}
    if (nfc.isEnabled()) { // be sure to check isEnabled() twice to recover binder
        nfc.enableReaderMode(this, ... );
    }
}

不幸的是,在某些设备上,从此类错误中恢复的唯一方法是手动强制停止 NFC 系统服务应用程序,甚至重新启动设备。

于 2019-04-15T14:29:43.040 回答
0

我没有崩溃的解决方案,但我有一些提示如何重现它。

坠机是如何造成的

此崩溃是由自动化测试环境触发的

android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)

并且很可能某些东西在活动重新创建之间没有持续/正确处理。

用仪器测试进行复制。

您可以通过文档了解如何编写仪器测试以重现它: https ://developer.android.com/reference/android/app/Instrumentation

在这篇文章中,有一些关于如何通过仪器测试处理活动生命周期的额外细节如何 在 android 仪器测试中停止和重新启动活动?

以用户身份进行复制。

当您将应用程序发送到后台时,这可能会在真实设备上发生,并且系统将其杀死以获取资源,因此当它再次将其带到前面时,某些内容分配不正确。

这里的困难在于,在测试时让系统杀死您的活动并不容易,因为如果另一个复杂的任务需要资源,则可能会发生这种情况,低端设备是此类测试的必要条件。

作为开发人员进行复制。

根据文档,简单的解决方法是使用开发人员选项下提供的“不保留活动”,这将在活动发送到后台时立即终止。

于 2019-04-10T22:22:14.213 回答