Skip to content

Commit 547c447

Browse files
authored
Merge pull request #219 from Akshya107/fix/nfc-handler-dead-thread
Fix: NFC Handler dead thread issue on Android SDK 35
2 parents 62f668c + f583e3f commit 547c447

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

android/src/main/kotlin/im/nfc/flutter_nfc_kit/FlutterNfcKitPlugin.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,13 @@ class FlutterNfcKitPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
8989
}
9090
}
9191
}
92-
if (!nfcHandler.post(handledFn)) {
92+
val looperThread = nfcHandler.looper?.thread
93+
if (looperThread == null || !looperThread.isAlive) {
94+
val thread = HandlerThread("FlutterNfcKit").apply { start() }
95+
nfcHandler = Handler(thread.looper)
96+
}
97+
val posted = nfcHandler.post(handledFn)
98+
if (!posted) {
9399
result.error("500", "Failed to post job to NFC Handler thread.", null)
94100
}
95101
}

0 commit comments

Comments
 (0)