Autore Topic: Errore "You must disable foreground dispatching while your activity is still ...  (Letto 3074 volte)

Offline wlf

  • Utente normale
  • ***
  • Post: 367
  • Respect: +8
    • Mostra profilo
  • Dispositivo Android:
    Xperia
Salve,
l'errore esatto è il seguente:
You must disable foreground dispatching while your activity is still resumed

Più in dettaglio lo stack-trace è il seguente:
Codice: [Seleziona]
java.lang.RuntimeException: Unable to pause activity {com.example.prova/com.example.prova.ScovaBtActivity}: java.lang.IllegalStateException: You must disable foreground dispatching while your activity is still resumed
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3074)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3029)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3007)
at android.app.ActivityThread.access$1000(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
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:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You must disable foreground dispatching while your activity is still resumed
at android.nfc.NfcAdapter.disableForegroundDispatchInternal(NfcAdapter.java:1182)
at android.nfc.NfcAdapter.disableForegroundDispatch(NfcAdapter.java:1168)
at com.example.prova.NFCForegroundUtil.disableForeground(NFCForegroundUtil.java:54)
at com.example.prova.CtrlBck.onPause(CtrlBck.java:71)
at com.example.prova.ScovaBtActivity.onPause(ScovaBtActivity.java:294)
at android.app.Activity.performPause(Activity.java:5379)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3060)
... 12 more
java.lang.IllegalStateException: You must disable foreground dispatching while your activity is still resumed
at android.nfc.NfcAdapter.disableForegroundDispatchInternal(NfcAdapter.java:1182)
at android.nfc.NfcAdapter.disableForegroundDispatch(NfcAdapter.java:1168)
at com.example.prova.NFCForegroundUtil.disableForeground(NFCForegroundUtil.java:54)
at com.example.prova.CtrlBck.onPause(CtrlBck.java:71)
at com.example.prova.ScovaBtActivity.onPause(ScovaBtActivity.java:294)
at android.app.Activity.performPause(Activity.java:5379)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1233)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3060)
at android.app.ActivityThread.performPauseActivity(ActivityThread.java:3029)
at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:3007)
at android.app.ActivityThread.access$1000(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
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:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
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:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
at com.example.prova.ConsumaActivity.onCreate(ConsumaActivity.java:197)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2250)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1200)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5105)
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:792)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:608)
at dalvik.system.NativeStart.main(Native Method)
at com.example.prova.ConsumaActivity.onCreate(ConsumaActivity.java:197)
at android.app.Activity.performCreate(Activity.java:5275)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2164)

Alla riga 54 di NFCForegroundUtil ho il seguente codice:
Codice: [Seleziona]
        public void disableForeground() {
                nfc.disableForegroundDispatch(activity);
        }

CtrlBck è una classe astratta che etende l'Activity ed alla riga 71 sono nella onPause:
Codice: [Seleziona]
                        nfcForegroundUtil.disableForeground();

Alla riga 294 della ScovaBtActivity sono sulla @Override della onPause.

Perché di dice che devo disabilitare il foreground dispatching mentre l'attività è ancora resumed? Io praticamente nella onResume faccio partire il listener del mio intentfilter e nella onPause lo interrompo, così come in questo esempio.