From 218a2e20ed3914a8917fd67b3a358e24629615ac Mon Sep 17 00:00:00 2001 From: xialiangwei Date: Mon, 28 Aug 2023 12:24:17 +0000 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0UIExtension=E4=B8=ADXTS?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xialiangwei Change-Id: Ifb40663431a9fba85dd0f3fac294db1c186b00f9 --- .../actsuiextensiontest/BUILD.gn | 2 +- .../src/main/ets/MainAbility/MainAbility.ts | 39 +++++---- .../src/main/ets/MainAbility2/MainAbility2.ts | 86 +++++++++--------- .../src/main/ets/MainAbility3/MainAbility3.ts | 87 ++++++++++--------- 4 files changed, 109 insertions(+), 105 deletions(-) diff --git a/ability/ability_runtime/actsuiextensiontest/BUILD.gn b/ability/ability_runtime/actsuiextensiontest/BUILD.gn index d1fc806ca..77fc6b057 100644 --- a/ability/ability_runtime/actsuiextensiontest/BUILD.gn +++ b/ability/ability_runtime/actsuiextensiontest/BUILD.gn @@ -17,9 +17,9 @@ group("actsuiextensiontest") { testonly = true if (is_standard_system) { deps = [ + "actsabilityusertest:StartAbilityByUIContentSession", "uiextensionprovider:UIExtensionProvider", "uiextensiontest:UIExtensionTest", - "actsabilityusertest:StartAbilityByUIContentSession", ] } } diff --git a/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility/MainAbility.ts b/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility/MainAbility.ts index 79ba798ea..05ee7a228 100644 --- a/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility/MainAbility.ts +++ b/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility/MainAbility.ts @@ -15,28 +15,29 @@ import Ability from '@ohos.app.ability.UIAbility' export default class MainAbility extends Ability { - onCreate(want, launchParam) { - console.log('MainAbility onCreate') - } - onDestroy() { - console.log('MainAbility onDestroy') - } + onCreate(want, launchParam) { + console.log('MainAbility onCreate'); + } - onWindowStageCreate(windowStage) { - console.log('MainAbility onWindowStageCreate') - windowStage.setUIContent(this.context, 'MainAbility/pages/index', null) - } + onDestroy() { + console.log('MainAbility onDestroy'); + } - onWindowStageDestroy() { - console.log('MainAbility onWindowStageDestroy') - } + onWindowStageCreate(windowStage) { + console.log('MainAbility onWindowStageCreate'); + windowStage.setUIContent(this.context, 'MainAbility/pages/index', null); + } - onForeground() { - console.log('MainAbility onForeground') - } + onWindowStageDestroy() { + console.log('MainAbility onWindowStageDestroy'); + } - onBackground() { - console.log('MainAbility onBackground') - } + onForeground() { + console.log('MainAbility onForeground'); + } + + onBackground() { + console.log('MainAbility onBackground'); + } }; \ No newline at end of file diff --git a/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility2/MainAbility2.ts b/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility2/MainAbility2.ts index 206293c06..fe36c2a15 100644 --- a/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility2/MainAbility2.ts +++ b/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility2/MainAbility2.ts @@ -12,60 +12,62 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Ability from '@ohos.app.ability.UIAbility' -import commonEventManager from '@ohos.commonEventManager' +import Ability from '@ohos.app.ability.UIAbility'; +import commonEventManager from '@ohos.commonEventManager'; -function PublishCallBackOne() { - console.log("====>Publish CallBack ACTS_StartAbility_0100_CommonEvent====>"); - globalThis.ability2Context.terminateSelf().then(()=>{ - console.log("====>terminateSelf success====>"); - }); +const sleepTimeOne = 1000; + +function publishCallBack() { + console.log('====>Publish CallBack ACTS_StartAbility_0100_CommonEvent====>'); + globalThis.ability2Context.terminateSelf().then(()=>{ + console.log('====>terminateSelf success====>'); + }); } function timeout() { - globalThis.ability2Context.startAbility( + globalThis.ability2Context.startAbility( { - bundleName: 'com.example.uiextensiontest', - abilityName: 'TestAbility', + bundleName: 'com.example.uiextensiontest', + abilityName: 'TestAbility', } - ).then(()=>{ - console.log("====>start com.example.uiextensiontest.TestAbility finish====>") - }); - } + ).then(()=>{ + console.log('====>start com.example.uiextensiontest.TestAbility finish====>'); + }); +} export default class MainAbility2 extends Ability { - onCreate(want, launchParam) { - console.log("MainAbility2 onCreate"); - } + onCreate(want, launchParam) { + console.log('MainAbility2 onCreate'); + } - onDestroy() { - // Ability is destroying, release resources for this ability - console.log("MainAbility2 onDestroy"); - } + onDestroy() { + // Ability is destroying, release resources for this ability + console.log('MainAbility2 onDestroy'); + } - onWindowStageCreate(windowStage) { - // Main window is created, set main page for this ability - console.log("MainAbility2 onWindowStageCreate"); - windowStage.setUIContent(this.context, "pages/index2", null); - } + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log('MainAbility2 onWindowStageCreate'); + windowStage.setUIContent(this.context, 'pages/index2', null); + } - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - console.log("MainAbility2 onWindowStageDestroy"); - } + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log('MainAbility2 onWindowStageDestroy'); + } - onForeground() { - // Ability has brought to foreground - console.log("MainAbility2 onForeground"); - globalThis.ability2Context = this.context; - setTimeout(timeout, 1000); - } + onForeground() { + // Ability has brought to foreground + console.log('MainAbility2 onForeground'); + globalThis.ability2Context = this.context; + setTimeout(timeout, sleepTimeOne); + } - onBackground() { - // Ability has back to background - console.log("MainAbility2 onBackground"); - let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult'; - commonEventManager.publish(onResultEvent, PublishCallBackOne); - } + onBackground() { + // Ability has back to background + console.log('MainAbility2 onBackground'); + let onResultEvent = 'ACTS_UIExtension_StartAbility_OnResult'; + commonEventManager.publish(onResultEvent, publishCallBack); + } }; diff --git a/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility3/MainAbility3.ts b/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility3/MainAbility3.ts index 28df4e28d..115b51e21 100644 --- a/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility3/MainAbility3.ts +++ b/ability/ability_runtime/actsuiextensiontest/actsabilityusertest/entry/src/main/ets/MainAbility3/MainAbility3.ts @@ -12,60 +12,61 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import Ability from '@ohos.app.ability.UIAbility' +import Ability from '@ohos.app.ability.UIAbility'; + +const sleepTimeOne = 1000; function timeout() { - globalThis.ability3Context.startAbility( + globalThis.ability3Context.startAbility( { - bundleName: 'com.example.uiextensiontest', - abilityName: 'TestAbility', + bundleName: 'com.example.uiextensiontest', + abilityName: 'TestAbility' } - ).then(()=>{ - console.log("====>start com.example.uiextensiontest.TestAbility finish====>") - }); - } + ).then(()=>{ + console.log('====>start com.example.uiextensiontest.TestAbility finish====>'); + }); +} export default class MainAbility3 extends Ability { - onCreate(want, launchParam) { - console.log("MainAbility3 onCreate"); - } + onCreate(want, launchParam) { + console.log('MainAbility3 onCreate'); + } - onDestroy() { - // Ability is destroying, release resources for this ability - console.log("MainAbility3 onDestroy"); - } + onDestroy() { + // Ability is destroying, release resources for this ability + console.log('MainAbility3 onDestroy'); + } - onWindowStageCreate(windowStage) { - // Main window is created, set main page for this ability - console.log("MainAbility3 onWindowStageCreate"); - windowStage.setUIContent(this.context, "pages/index3", null); - } + onWindowStageCreate(windowStage) { + // Main window is created, set main page for this ability + console.log('MainAbility3 onWindowStageCreate'); + windowStage.setUIContent(this.context, 'pages/index3', null); + } - onWindowStageDestroy() { - // Main window is destroyed, release UI related resources - console.log("MainAbility3 onWindowStageDestroy"); - } + onWindowStageDestroy() { + // Main window is destroyed, release UI related resources + console.log('MainAbility3 onWindowStageDestroy'); + } - onForeground() { - // Ability has brought to foreground - console.log("MainAbility3 onForeground"); - globalThis.ability3Context = this.context; - setTimeout(timeout, 1000); - - } + onForeground() { + // Ability has brought to foreground + console.log('MainAbility3 onForeground'); + globalThis.ability3Context = this.context; + setTimeout(timeout, sleepTimeOne); + } - onBackground() { - // Ability has back to background - console.log("MainAbility3 onBackground"); - globalThis.ability3Context.terminateSelfWithResult( - { - resultCode:1, - want:{ - action:'ACTION' + onBackground() { + // Ability has back to background + console.log('MainAbility3 onBackground'); + globalThis.ability3Context.terminateSelfWithResult( + { + resultCode:1, + want:{ + action:'ACTION' } - },()=>{ - console.debug("====>terminateSelfWithResult success====>") - }); - } + }, ()=>{ + console.debug('====>terminateSelfWithResult success====>'); + }); + } }; -- GitLab