What are the possible reasons for NFC Service to become dead after some time?
Asked Answered
A

2

6

We are using NFC tags as parking tickets for entry and exit. On each entry, the tag is written with some data and at the exit that data verifies the exit of the vehicle.

After entry and exit of some vehicles, the NfcService becomes dead, and the smartphone is unable to detect NFC tags. The device needs a reboot to restart NfcService and the device starts working fine again.

This error is seen at random and we have been unable to reproduce this error in the development environment, but we have observed this issue several times on the devices installed at entry and exit gates of parking areas.

We were able to manage the above log somehow when we were debugging this issue.

We have tried different changes like using enableReaderMode instead of enableForegroundDispatch, but the issue persists.

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 and NFCReadFragment internally read and write NDEF data to the tags.

Similar questions on StackOverflow:

UPDATE

Shifted the code from onResume, so the activity is always active and visible when enableReadeMode() and disableReaderMode() is called

Here are the new logs

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

Doesn't seem to be a case of activity recreation now. Everytime we expect NFC tag to be connected we call enableReaderMode and we call disableReaderMode as soon as our work with the tag is over.

The device being used at the customer end is Telpo 900B.

Ator answered 10/4, 2019 at 21:55 Comment(4)
Did you achieve to resolve this? How?Solitary
We changed the device. The issue wasn't completely resolved but the frequency of this happening reduced drastically. Haven't been able to find a permanent solution yet.Ator
Using the approach of perform isEnabled twice?Solitary
Yup, even with isEnabled twice approach the issue isn't resolvedAtor
M
1

The error E/NFC: NFC service dead - attempting to recover typically occurs when there is poor connectivity between the tag and the Android device (i.e. when communication is interrupted and the NFC service is unable to recover from the error). In those (rare?) cases the NFC service crashes and tries to restart.

In some cases, you may be able to recover from that error from within the app by re-registering for the foreground dispatch / reader mode, e.g. using

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, ... );
    }
}

Unfortunately, on some devices the only way to recover from that type of error is to manually force-stop the NFC system service app or to even reboot the device.

Mohur answered 15/4, 2019 at 14:29 Comment(0)
P
0

I don't have a solution for the crash but I have some tips how to reproduce it.

How the crash is caused

This crash is from automation testing environment triggered by

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

And most probably something does not persist/handled correctly between the activity re-creations.

Reproduction with instumentation test.

You can get though documentation to see how to write instumentation tests in order to reproduce it: https://developer.android.com/reference/android/app/Instrumentation

At this post there are some extra details of how to handle activity lifecycle via instrumentation tests How to stop and restart an activity in an android instrumentation test?

Reproduction on as a user.

This can happen on a real device when you send the application to background, and the system kill it to gain resources, so when it brought again at front something is not allocated correctly.

The hard thing here is that its not easy to make the system kill your activity while testing as this may happen if another intesive task requires resourses, a low end device is a must for such a test.

Reproduction on as a developer.

According to documentation the easy workaround is to use the "Don't keep activities" provided under developer options which will kill the activity as soon as it send to background.

Polito answered 10/4, 2019 at 22:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.