解决蓝牙耳机界面内存泄漏问题
authorluozheng <1732036298@qq.com>
Sat, 5 Oct 2024 11:35:36 +0000 (19:35 +0800)
committerluozheng <1732036298@qq.com>
Sat, 5 Oct 2024 11:35:36 +0000 (19:35 +0800)
解决蓝牙耳机界面,如果进入搜索界面开启定时器后,按按键未关闭定时器问题

code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp
code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/TipsConnFailMessageView.cpp

index f945029..5be4c75 100644 (file)
@@ -17,10 +17,14 @@ namespace OHOS {
 BluetoothDeviceCaseListAdapter::~BluetoothDeviceCaseListAdapter()
 {
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceCaseListAdapter::~BluetoothDeviceCaseListAdapter");
-    UIView::OnClickListener *click = item->GetOnClickListener();
-    if (click != nullptr) {
-        delete click;
-        click = nullptr;
+    // UIView::OnClickListener *click = item->GetOnClickListener();
+    // if (click != nullptr) {
+    //     delete click;
+    //     click = nullptr;
+    // }
+    if (listener != nullptr) {
+        delete listener;
+        listener = nullptr;
     }
 }
 
index aa5f2ff..5032177 100644 (file)
@@ -244,6 +244,15 @@ bool BluetoothPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
     // 如果是power键就返回上一级\r
     if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)\r
     {\r
+        //如果是按键退出,退出时需要做一些清理工作\r
+        BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance();\r
+        if(bluetoothEarPhoneView)\r
+        {\r
+            bluetoothEarPhoneView->BtAnimatorStop(); //停止搜索动画\r
+            bluetoothEarPhoneView->StopBtDiscovery();//停止定时器\r
+            BluetoothModel::GetInstance()->SetTagConnectView(false); //清除标志位\r
+            BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false);\r
+        }\r
         NativeAbility::GetInstance().Back();\r
     }\r
     return true;\r
index 8d12587..5fdfd13 100644 (file)
@@ -46,6 +46,16 @@ namespace OHOS
                 delete tipLabel;\r
                 tipLabel = nullptr;\r
             }\r
+            if (conn_fail_Label)\r
+            {\r
+                delete conn_fail_Label;\r
+                conn_fail_Label = nullptr;\r
+            }\r
+            if (bluetoothNameLabel)\r
+            {\r
+                delete bluetoothNameLabel;\r
+                bluetoothNameLabel = nullptr;\r
+            }\r
             delete group;\r
             group = nullptr;\r
         }\r