我们将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的类似问题:
enableReadeMode()
和disableReaderMode()
时,活动始终处于活动状态并可见将代码从onResume中移出,因此在调用enableReadeMode()
和disableReaderMode()
时,活动始终处于活动状态并可见
这是新的日志
04-15 01:51:50.328 4987-4987/in.parksmart.operator D/WindowClient: Add to mViews: com.android.internal.policy.PhoneWindow$DecorView{55c53ae V.E...... R.....I. 0,0-0,0}, this = 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: hardware acceleration is enabled, this = 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 initialize window=0x9de38208, title=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] format: 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: register, handle(0x9c9cd8e0) (w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:51.181 4987-4999/in.parksmart.operator D/WTF: Disabling reader mode 04-15 01:51:51.182 4987-4999/in.parksmart.operator D/WTF : NFC: Incompatible Tag 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: unregister, handle(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] format: 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: register, handle(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 woken up by a token 04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto: sslSelect, appData=0xaf928a00 read ret=1 04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto: sslSelect, appData=0xaf928a00 woken up by a token 04-15 01:51:51.459 4987-5052/in.parksmart.operator D/NativeCrypto: sslSelect, appData=0xaf928a00 read ret=1 04-15 01:51:54.335 4987-5037/in.parksmart.operator D/GraphicBuffer: register, handle(0x9d9715a0) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:54.414 4987-4987/in.parksmart.operator D/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0 04-15 01:51:54.414 4987-4987/in.parksmart.operator D/WTF: Enabling reader mode 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: unregister, handle(0x9c9cd8e0) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:54.468 4987-5037/in.parksmart.operator D/GraphicBuffer: unregister, handle(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] format: 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: register, handle(0x9d9715a0) (w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:54.485 4987-5037/in.parksmart.operator D/GraphicBuffer: register, handle(0x9c9cd8e0) (w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:54.506 4987-5037/in.parksmart.operator D/GraphicBuffer: register, handle(0x9d971610) (w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:54.542 4987-5037/in.parksmart.operator D/GraphicBuffer: register, handle(0x9d971680) (w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:54.976 4987-5000/in.parksmart.operator D/WTF: Disabling reader mode 04-15 01:51:54.977 4987-5000/in.parksmart.operator D/WTF : NFC: Incompatible Tag 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: unregister, handle(0x9d9715a0) (w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:55.004 4987-5037/in.parksmart.operator D/GraphicBuffer: unregister, handle(0x9c9cd8e0) (w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:55.005 4987-5037/in.parksmart.operator D/GraphicBuffer: unregister, handle(0x9d971610) (w:656 h:497 s:656 f:0x1 u:0x000f02) 04-15 01:51:55.005 4987-5037/in.parksmart.operator D/GraphicBuffer: unregister, handle(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] format: 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: register, handle(0x9d971680) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:56.966 4987-5037/in.parksmart.operator D/GraphicBuffer: register, handle(0x9d971610) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:57.023 4987-5037/in.parksmart.operator D/GraphicBuffer: register, handle(0x9c9cd8e0) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:51:57.118 4987-4987/in.parksmart.operator D/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0 04-15 01:51:57.119 4987-4987/in.parksmart.operator D/WTF: Enabling reader mode 04-15 01:52:05.451 4987-4987/in.parksmart.operator E/NFC: NFC service dead - attempting to recover android.os.DeadObjectException at android.os.BinderProxy.transactNative(Native Method) at android.os.BinderProxy.transact(Binder.java:511) at android.nfc.INfcAdapter$Stub$Proxy.setReaderMode(INfcAdapter.java:614) at android.nfc.NfcActivityManager.setReaderMode(NfcActivityManager.java:241) at android.nfc.NfcActivityManager.enableReaderMode(NfcActivityManager.java:217) at android.nfc.NfcAdapter.enableReaderMode(NfcAdapter.java:1299) at in.parksmart.operator.NFCReadFragment.enableReaderMode(NFCReadFragment.java:131) at in.parksmart.operator.NFCReadFragment$1.onClick(NFCReadFragment.java:100) at android.view.View.performClick(View.java:5265) at android.view.View$PerformClick.run(View.java:21534) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5728) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 04-15 01:52:05.452 4987-4987/in.parksmart.operator E/NFC: could not retrieve NFC service during service recovery 04-15 01:52:05.454 4987-4987/in.parksmart.operator I/Choreographer: Skipped 432 frames! The application may be doing too much work on its main thread. 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: unregister, handle(0x9d971680) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:52:05.474 4987-5037/in.parksmart.operator D/GraphicBuffer: unregister, handle(0x9d971610) (w:584 h:593 s:592 f:0x1 u:0x000f02) 04-15 01:52:05.475 4987-5037/in.parksmart.operator D/GraphicBuffer: unregister, handle(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] format: 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: register, handle(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: unregister, handle(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: Remove from mViews: com.android.internal.policy.PhoneWindow$DecorView{55c53ae V.E...... R......D 0,0-528,369}, this = android.view.WindowManagerGlobal@ff3d558 04-15 01:52:05.516 4987-4987/in.parksmart.operator W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 04-15 01:52:05.517 4987-4987/in.parksmart.operator W/ViewRootImpl: Dropping event due to root view being removed: 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, source=0x1002 } 04-15 01:52:05.517 4987-4987/in.parksmart.operator W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 04-15 01:52:05.518 4987-4987/in.parksmart.operator W/ViewRootImpl: Dropping event due to root view being removed: 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, source=0x1002 } 04-15 01:52:05.518 4987-4987/in.parksmart.operator W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 04-15 01:52:05.519 4987-4987/in.parksmart.operator W/ViewRootImpl: Dropping event due to root view being removed: 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, deviceId=2, source=0x1002 } 04-15 01:52:05.520 4987-4987/in.parksmart.operator W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 04-15 01:52:05.520 4987-4987/in.parksmart.operator W/ViewRootImpl: Dropping event due to root view being removed: 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, deviceId=2, source=0x1002 } 04-15 01:52:05.520 4987-4987/in.parksmart.operator W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 04-15 01:52:05.521 4987-4987/in.parksmart.operator W/ViewRootImpl: Dropping event due to root view being removed: 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, deviceId=2, source=0x1002 } 04-15 01:52:05.521 4987-4987/in.parksmart.operator W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 04-15 01:52:05.521 4987-4987/in.parksmart.operator W/ViewRootImpl: Dropping event due to root view being removed: 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, deviceId=2, source=0x1002 } 04-15 01:52:05.521 4987-4987/in.parksmart.operator W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 04-15 01:52:05.522 4987-4987/in.parksmart.operator W/ViewRootImpl: Dropping event due to root view being removed: 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, deviceId=2, source=0x1002 } 04-15 01:52:05.522 4987-4987/in.parksmart.operator W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 04-15 01:52:05.522 4987-4987/in.parksmart.operator W/ViewRootImpl: Dropping event due to root view being removed: 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, deviceId=2, source=0x1002 } 04-15 01:52:05.522 4987-4987/in.parksmart.operator W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed. 04-15 01:52:06.898 4987-4987/in.parksmart.operator D/SettingsInterface: from settings cache , name = sound_effects_enabled , value = 0 04-15 01:52:06.899 4987-4987/in.parksmart.operator E/NFC: NFC service dead - attempting to recover android.os.DeadObjectException at android.os.BinderProxy.transactNative(Native Method) at android.os.BinderProxy.transact(Binder.java:511) at android.nfc.INfcAdapter$Stub$Proxy.getState(INfcAdapter.java:365) at android.nfc.NfcAdapter.isEnabled(NfcAdapter.java:642) at in.parksmart.operator.MainActivity$PlaceholderFragment.lambda$onCreateView$4(MainActivity.java:2925) at in.parksmart.operator.-$$Lambda$MainActivity$PlaceholderFragment$rsZBvNO0FFN0PjGCm8QiSvrhIqw.onClick(lambda) at android.view.View.performClick(View.java:5265) at android.view.View$PerformClick.run(View.java:21534) at android.os.Handler.handleCallback(Handler.java:815) at android.os.Handler.dispatchMessage(Handler.java:104) at android.os.Looper.loop(Looper.java:207) at android.app.ActivityThread.main(ActivityThread.java:5728) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 04-15 01:52:06.941 4987-4987/in.parksmart.operator D/WindowClient: Add to mViews: com.android.internal.policy.PhoneWindow$DecorView{dcd6d0c V.E...... R.....I. 0,0-0,0}, this = 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: hardware acceleration is enabled, this = 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 initialize window=0x9de38208, title=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] format: 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: register, handle(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 upload: x, y, width height = 0, 0, 1024, 512 04-15 01:52:07.025 4987-5037/in.parksmart.operator D/GraphicBuffer: register, handle(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: Child Removed 04-15 01:52:13.729 4987-4987/in.parksmart.operator D/FBDB: Child Removed 04-15 01:52:13.729 4987-4987/in.parksmart.operator D/FBDB: Child removed
现在似乎不是娱乐活动的案例。
每次我们期望连接NFC标签时,我们都会调用enableReaderMode
,并且一旦使用标签结束,我们就会调用disableReaderMode
。
在客户端使用的设备是Telpo 900B。
答案 0 :(得分:1)
错误 E / NFC:NFC服务失效-尝试恢复通常发生在标签与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系统服务应用程序,甚至重新启动设备。
答案 1 :(得分:0)
我没有崩溃的解决方案,但是我有一些技巧来重现它。
崩溃的原因
此崩溃是由以下原因触发的自动化测试环境
android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1150)
在两次活动重新创建之间很可能无法正确持久/处理某些事情。
带乐器测试的复制。
您可以通过文档来了解如何编写仪器测试以重现它: https://developer.android.com/reference/android/app/Instrumentation
在这篇文章中,有一些关于如何通过仪器测试处理活动生命周期的额外详细信息 How to stop and restart an activity in an android instrumentation test?
以用户身份进行复制。
当您将应用程序发送到后台并且系统杀死它以获取资源时,这可能会在真实设备上发生,因此当它再次出现在前端时,某些内容将无法正确分配。
这里的难点在于,要使系统在测试时杀死您的活动并不容易,因为如果另一项艰巨的任务需要资源,则可能会发生这种情况,低端设备是此类测试所必需的。
以开发者身份进行复制。
根据文档,简单的解决方法是使用开发人员选项下提供的“ Don't keep activities”,一旦活动发送到后台,该活动就会被杀死。