diff --git a/frameworks/native/ability/native/ui_ability.cpp b/frameworks/native/ability/native/ui_ability.cpp index 5b438dea81..8a227a10c8 100644 --- a/frameworks/native/ability/native/ui_ability.cpp +++ b/frameworks/native/ability/native/ui_ability.cpp @@ -227,6 +227,9 @@ void UIAbility::OnStop() return; } lifecycle_->DispatchLifecycle(AppExecFwk::LifeCycle::Event::ON_STOP); +#ifdef SUPPORT_SCREEN + Rosen::DisplayManager::GetInstance().RemoveDisplayIdFromAms(token_); +#endif TAG_LOGD(AAFwkTag::UIABILITY, "end"); } @@ -1036,6 +1039,9 @@ void UIAbility::OnStartForSupportGraphics(const AAFwk::Want &want) int32_t displayId = want.GetIntParam(AAFwk::Want::PARAM_RESV_DISPLAY_ID, defualtDisplayId); TAG_LOGD(AAFwkTag::UIABILITY, "abilityName: %{public}s, displayId: %{public}d", abilityInfo_->name.c_str(), displayId); +#ifdef SUPPORT_SCREEN + Rosen::DisplayManager::GetInstance().AddDisplayIdFromAms(displayId, token_); +#endif auto option = GetWindowOption(want); InitWindow(displayId, option); diff --git a/frameworks/native/appkit/app/main_thread.cpp b/frameworks/native/appkit/app/main_thread.cpp index ce54b27005..7d3b0e737a 100644 --- a/frameworks/native/appkit/app/main_thread.cpp +++ b/frameworks/native/appkit/app/main_thread.cpp @@ -2058,6 +2058,15 @@ void MainThread::HandleLaunchAbility(const std::shared_ptr & AbilityThread::AbilityThreadMain(application, abilityRecord, mainHandler_->GetEventRunner(), stageContext); #endif }; +#ifdef SUPPORT_SCREEN + Rosen::DisplayId defaultDisplayId = Rosen::DisplayManager::GetInstance().GetDefaultDisplayId(); + Rosen::DisplayId displayId = defaultDisplayId; + if (abilityRecord->GetWant() != nullptr) { + displayId = abilityRecord->GetWant()->GetIntParam(AAFwk::Want::PARAM_RESV_DISPLAY_ID, defaultDisplayId); + } + Rosen::DisplayManager::GetInstance().AddDisplayIdFromAms(displayId, abilityRecord->GetToken()); + TAG_LOGD(AAFwkTag::APPKIT, "add displayId: %{public}" PRIu64, displayId); +#endif bool isAsyncCallback = false; std::shared_ptr stageContext = application_->AddAbilityStage( abilityRecord, callback, isAsyncCallback);