harryjph / android-bluetooth-serial

A library for Android to simplify basic serial communication over Bluetooth, for example when communicating with Arduinos.
Apache License 2.0
176 stars 60 forks source link

BluetoothManager.getInstance() never null #13

Open gbkwiatt opened 4 years ago

gbkwiatt commented 4 years ago

It;s probably because I am new to Android / Kotlin.

Trying to make a use of that module, So far working fine with list and bluetooth enabled. I have part of code that checks the instance as in readme:

private var bluetoothManager: BluetoothManager? =BluetoothManager.getInstance()
  override fun onCreate(savedInstanceState: Bundle?) {
    if (bluetoothManager == null) {}
}

But Android studio gives me a hint, that bluetoothManager is never null

harryjph commented 4 years ago

That's strange, in the Kotlin rewrite it looks like this:

https://github.com/harry1453/android-bluetooth-serial/blob/a2075b9444dae1ed6b934d23da78262d48bfb994/androidBluetoothSerial/src/main/java/com/harrysoft/androidbluetoothserial/BluetoothManager.kt#L78

And is quite clearly nullable.