harmony 鸿蒙LifecycleApp接口切换

  • 2022-12-13
  • 浏览 (631)

LifecycleApp接口切换

FA模型接口 Stage模型接口对应d.ts文件 Stage模型对应接口
onShow?(): void; \@ohos.window.d.ts on(eventType: ‘windowStageEvent’, callback: Callback<WindowStageEventType>): void;
监听FOREGROUND切到前台状态
onHide?(): void; \@ohos.window.d.ts on(eventType: ‘windowStageEvent’, callback: Callback<WindowStageEventType>): void;
监听BACKGROUND切到后台状态
onDestroy?(): void; \@ohos.app.ability.UIAbility.d.ts onDestroy(): void;
onCreate?(): void; \@ohos.app.ability.UIAbility.d.ts onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;
onWindowDisplayModeChanged?(isShownInMultiWindow: boolean, newConfig: resourceManager.Configuration): void; Stage模型无对应接口 暂时未提供对应接口
onStartContinuation?(): boolean; Stage模型无对应接口 Stage模型上,应用无需感知迁移是否成功(由应用发起迁移请求时感知),onStartContinuation废弃
onSaveData?(data: Object): boolean; \@ohos.app.ability.UIAbility.d.ts onContinue(wantParam : {[key: string]: Object}): AbilityConstant.OnContinueResult;
onCompleteContinuation?(result: number): void; application\ContinueCallback.d.ts onContinueDone(result: number): void;
onRestoreData?(data: Object): void; \@ohos.app.ability.UIAbility.d.ts onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;
onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;
多实例模式Ability迁移目标端在onCreate回调中完成数据恢复,单实例模式应用迁移目标端在onCreate回调中完成数据恢复,回调中通过判断launchParam.launchReason可获取迁移启动的场景,从而可以从Want中获取迁移前保存的数据
onRemoteTerminated?(): void; application\ContinueCallback.d.ts onContinueDone(result: number): void;
onSaveAbilityState?(outState: PacMap): void; \@ohos.app.ability.UIAbility.d.ts onSaveState(reason: AbilityConstant.StateType, wantParam : {[key: string]: Object}): AbilityConstant.OnSaveResult;
onRestoreAbilityState?(inState: PacMap): void; \@ohos.app.ability.UIAbility.d.ts onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void;
应用重启后会触发Ability的onCreate方法,通过判断launchParam.launchReason可获取自恢复的场景,从而可以从Want中获取重启前保存的数据
onInactive?(): void; \@ohos.app.ability.UIAbility.d.ts onBackground(): void;
onActive?(): void; \@ohos.app.ability.UIAbility.d.ts onForeground(): void;
onNewWant?(want: Want): void; \@ohos.app.ability.UIAbility.d.ts onNewWant(want: Want, launchParam: AbilityConstant.LaunchParam): void;
onMemoryLevel?(level: number): void \@ohos.app.ability.UIAbility.d.ts onMemoryLevel(level: AbilityConstant.MemoryLevel): void;

你可能感兴趣的鸿蒙文章

harmony 鸿蒙应用模型

harmony 鸿蒙使用显式Want启动应用组件

harmony 鸿蒙使用隐式Want打开网址

harmony 鸿蒙AbilityStage组件容器

harmony 鸿蒙访问DataAbility

harmony 鸿蒙FA模型访问Stage模型DataShareExtensionAbility

harmony 鸿蒙AccessibilityExtensionAbility

harmony 鸿蒙常见action与entities

harmony 鸿蒙API切换概述

harmony 鸿蒙app和deviceConfig的切换

0  赞