diff --git a/ability/ability_runtime/actsqueryfunctiontest/actsgetcurrenttopabilitystagebtest/entry/src/main/ets/Ability1/Ability1.ts b/ability/ability_runtime/actsqueryfunctiontest/actsgetcurrenttopabilitystagebtest/entry/src/main/ets/Ability1/Ability1.ts index bb7ab237930ac0e040e63c455d5041b312ddda2b..ea11ae24a115a0c9567172fb9410cccf7ac88512 100644 --- a/ability/ability_runtime/actsqueryfunctiontest/actsgetcurrenttopabilitystagebtest/entry/src/main/ets/Ability1/Ability1.ts +++ b/ability/ability_runtime/actsqueryfunctiontest/actsgetcurrenttopabilitystagebtest/entry/src/main/ets/Ability1/Ability1.ts @@ -36,6 +36,13 @@ export default class MainAbility extends Ability { globalThis.ability3Context = this.context windowStage.setUIContent(this.context, "pages/index1", null) + windowStage.on('windowStageEvent', (data) => { + console.log(`ActsGetCurrentTopAbilityStagebTest onWindwoStage is : ${JSON.stringify(data)}`) + if (data == 2 ) { + console.log(`ActsGetCurrentTopAbilityStagebTest getWindowStageActive is sucess`) + commonEvent.publish("GetCurrentTopAbility", publishCallBackOne); + } + }) } onWindowStageDestroy() { @@ -46,7 +53,6 @@ export default class MainAbility extends Ability { onForeground() { // Ability has brought to foreground console.log("Ability1 onForeground") - commonEvent.publish("GetCurrentTopAbility", publishCallBackOne); } diff --git a/ability/ability_runtime/apitest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/apitest/entry/src/main/ets/MainAbility/MainAbility.ts index e7b2eeb8fed9163f149f712f9c74e1aa1903c8bf..733c7477e3e56c1858a08a5346b33dd088ab2a5f 100644 --- a/ability/ability_runtime/apitest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/apitest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -36,7 +36,20 @@ export default class TestAbility extends Ability { onWindowStageCreate(windowStage) { console.log('TestAbility onWindowStageCreate') + globalThis.onWindowStageActive = false; + let count = 0; windowStage.setUIContent(this.context, 'MainAbility/pages/index', null) + windowStage.on('windowStageEvent', (data) => { + console.log(`ActsApiTest onWindwoStage is : ${JSON.stringify(data)}`) + if (data == 2 ) { + console.log(`ActsApiTest onWindwoStage count is : ${count}`) + count++; + if (count == 2) { + console.log(`ActsApiTest onWindwoStage count is : ${count}`) + globalThis.onWindowStageActive = true; + } + } + }) } onWindowStageDestroy() { diff --git a/ability/ability_runtime/apitest/entry/src/main/ets/test/Ability.test.ets b/ability/ability_runtime/apitest/entry/src/main/ets/test/Ability.test.ets index 7784ab65062026af5f68b2ea4dd9c84516d5e0cd..f1a78a73901535a8f71d3704a4986bf29a309193 100644 --- a/ability/ability_runtime/apitest/entry/src/main/ets/test/Ability.test.ets +++ b/ability/ability_runtime/apitest/entry/src/main/ets/test/Ability.test.ets @@ -31,7 +31,18 @@ export default function abilityTest() { describe('ActsChangeAbilityStagetest', function () { beforeAll(async function (done) { console.info('beforeAll called') - await sleep(2000) + let delay = 3000; + let start = new Date().getTime(); + while (true) { + if (globalThis.onWindowStageActive) { + console.log(`ActsApiTest getWindwoStageActive is success`) + break; + } + if (new Date().getTime() - start > delay) { + console.log(`ActsApiTest getWindwoStageActive is failed`) + break; + } + } await globalThis.abilitydelegator.getCurrentTopAbility().then((data) => { mainability = data done()