From 09662c014144144782f72cd6b4e2b16b3372ff8b Mon Sep 17 00:00:00 2001 From: andrekir Date: Mon, 3 Apr 2023 18:30:54 -0300 Subject: [PATCH] fix: removeObservers when onStop is called (UI not visible) --- .../main/java/com/geeksville/mesh/MainActivity.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index 1f50efd24..86000ceec 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -210,10 +210,6 @@ class MainActivity : AppCompatActivity(), Logging { tab.icon = ContextCompat.getDrawable(this, tabInfos[position].icon) }.attach() - model.connectionState.observe(this) { connected -> - updateConnectionStatusImage(connected) - } - // Handle any intent handleIntent(intent) } @@ -638,6 +634,11 @@ class MainActivity : AppCompatActivity(), Logging { unregisterMeshReceiver() // No point in receiving updates while the GUI is gone, we'll get them when the user launches the activity unbindMeshService() + scanModel.changeDeviceAddress.removeObservers(this) + model.connectionState.removeObservers(this) + bluetoothViewModel.enabled.removeObservers(this) + model.requestChannelUrl.removeObservers(this) + super.onStop() } @@ -658,6 +659,10 @@ class MainActivity : AppCompatActivity(), Logging { } } + model.connectionState.observe(this) { connected -> + updateConnectionStatusImage(connected) + } + bluetoothViewModel.enabled.observe(this) { enabled -> if (!enabled && !requestedEnable && scanModel.selectedBluetooth) { requestedEnable = true