Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,16 @@ class FlutterPosPrinterPlatformPlugin : FlutterPlugin, MethodCallHandler, Plugin
messageChannel = null
messageUSBChannel = null

bluetoothService.setHandler(null)
adapter.setHandler(null)
// Check if bluetoothService is initialized before cleanup
// This prevents crash when BackgroundService stops before onAttachedToActivity is called
if (::bluetoothService.isInitialized) {
bluetoothService.setHandler(null)
}

// Check if adapter is initialized before cleanup
if (::adapter.isInitialized) {
adapter.setHandler(null)
}
}

override fun onAttachedToActivity(binding: ActivityPluginBinding) {
Expand Down Expand Up @@ -227,21 +235,30 @@ class FlutterPosPrinterPlatformPlugin : FlutterPlugin, MethodCallHandler, Plugin
override fun onDetachedFromActivityForConfigChanges() {
Log.d(TAG, "onDetachedFromActivityForConfigChanges")
currentActivity = null
bluetoothService.setActivity(null)
// Check if bluetoothService is initialized before cleanup
if (::bluetoothService.isInitialized) {
bluetoothService.setActivity(null)
}
}

override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
Log.d(TAG, "onReattachedToActivityForConfigChanges")
currentActivity = binding.activity
binding.addRequestPermissionsResultListener(this)
binding.addActivityResultListener(this)
bluetoothService.setActivity(currentActivity)
// Check if bluetoothService is initialized before setting activity
if (::bluetoothService.isInitialized) {
bluetoothService.setActivity(currentActivity)
}
}

override fun onDetachedFromActivity() {
Log.d(TAG, "onDetachedFromActivity")
currentActivity = null
bluetoothService.setActivity(null)
// Check if bluetoothService is initialized before cleanup
if (::bluetoothService.isInitialized) {
bluetoothService.setActivity(null)
}
}

override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
Expand Down