GPS的开关使用异步执行
authorCaisking <Casiking@zhihuishixun.com>
Fri, 26 Dec 2025 10:59:05 +0000 (18:59 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Fri, 26 Dec 2025 10:59:05 +0000 (18:59 +0800)
code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp

index 699bd39..07fb856 100644 (file)
  void TraingModel::stop_heart_gps() {
    if (gpsopen == true) {
      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开始关闭GPS定位服务...");
-     // 关闭gps
- #if defined(SUPPORT_GNSS)
-     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "调用gnss_stop()关闭GPS服务");
-     gnss_stop();
-     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gnss_stop()调用完成");
- #endif
+    // 关闭gps
+#if defined(SUPPORT_GNSS)
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "调用gnss_stop()关闭GPS服务");
+    GraphicService::GetInstance()->PostGraphicEvent([]() {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "异步执行gnss_stop()");
+      gnss_stop();
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gnss_stop()调用完成");
+    });
+#endif
  
      //关闭心率检测
  #ifdef SUPPORT_PPG_SERVICE
    if (gps_timer_count < 2) {
      return;
    }
-   if (gps_timer_count == 2) {
- #if defined(SUPPORT_GNSS)
-     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开启gps");
-     gnss_start();
- #endif
-   }
+  if (gps_timer_count == 2) {
+#if defined(SUPPORT_GNSS)
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "开启gps");
+    GraphicService::GetInstance()->PostGraphicEvent([]() {
+      WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "异步执行gnss_start()");
+      gnss_start();
+    });
+#endif
+  }
  #if defined(SUPPORT_GNSS)
    gps_data_t send_gps_data = {0};
    gps_data_t *gps_data = getPGPSGlobaldata();
index f02755c..527a405 100644 (file)
@@ -8,6 +8,7 @@
 #include "custom_utils.h"\r
 #include "common/key_code.h"\r
 \r
+#include <cstddef>\r
 #include <iostream>\r
 #include <chrono>\r
 #include <thread>\r
@@ -159,6 +160,10 @@ namespace OHOS
     //修改为秒级定时器更新GPS定位状态\r
     void TraingNomalPresenter::OnTickEvent()\r
     {\r
+        if(TraingNomalView::GetInstance() == nullptr)\r
+        {\r
+            return;\r
+        }\r
         /*判断是否需要GPS*/\r
         if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == false)\r
         {\r