ln-12 / multiplatform-connectivity-status

A Kotlin multiplatform mobile library to monitor the connectivity status of the device
Apache License 2.0
61 stars 2 forks source link

stop function does not unregister the network callback in android #3

Closed davidoskky closed 1 year ago

davidoskky commented 1 year ago

Hi, I'm testing this in android api 31, I'm not sure if this problem is also present on other android versions. If I start the connectivity status, stop it and then start it again I get this error message:

E/ConnectivityManager: NetworkCallback was already registered

Apparently the networkCallback is not being unregistered when I call the stop function.

I believe this is related to this line https://github.com/ln-12/multiplatform-connectivity-status/blob/7684f38d74c67db96449334b5e9b7d14e415fa7f/src/androidMain/kotlin/com/github/ln-12/library/ConnectivityStatus.kt#L30

A new local ConnectivityManager object appears to be generated every time you call the start() function, thus it is never stored within the ConnectivityStatus object and it cannot be used to unregister the callback.

ln-12 commented 1 year ago

You are totally right. I must have forgotten this part during some refactoring. Thank you!

ln-12 commented 1 year ago

Your fix is now available in v1.3.0.