openharmony 鸿蒙 changelogs-ability

2023-06-24 浏览 (357)

Ability Framework Changelog

Added the saveAppState API to cl.ability.appRecovery

The API saveAppState (context?: UIAbilityContext): boolean; is added.

Change Impact

When developing an application based on OpenHarmony 4.0.5.2 or a later SDK version, you can use saveAppState with the ability context specified to save the state of the specified ability.

Key API/Component Changes

The saveAppState API is added to the @ohos.app.ability.appRecovery.d.ts file.

ModuleClassMethod/Attribute/Enum/ConstantChange Type
@ohos.app.ability.appRecovery.d.tsappRecoverysaveAppState(context?: UIAbilityContext): boolean;Added

Adaptation Guide

Call saveAppState with the UIAbility context specified to save the ability state.

import appRecovery from '@ohos.app.ability.appRecovery';
onBackground() {
    hilog.info(0x0000, '[demo]', '%{public}s', 'EntryAbility onBackground');
    appRecovery.saveAppState(this.context)
}

Added the setRestartWant API to cl.ability.appRecovery.

The API setRestartWant (want: Want): void; is added.

Change Impact

To develop an application based on OpenHarmony 4.0.5.2 or a later SDK version, you can use setRestartWant to set the ability to recover.

Key API/Component Changes

The setRestartWant API is added to the @ohos.app.ability.appRecovery.d.ts file.

ModuleClassMethod/Attribute/Enum/ConstantChange Type
@ohos.app.ability.appRecovery.d.tsappRecoverysetRestartWant(want: Want): void;Added

Adaptation Guide

Call setRestartWant to set the ability to recover.

import appRecovery from '@ohos.app.ability.appRecovery';
Button ("Start to Recover Ability")
    .fontSize(40)
    .fontWeight(FontWeight.Bold)
    .onClick(()=> {
        // set restart want
        let want = {
            bundleName: "ohos.samples.recovery",
            abilityName: "RecoveryAbility"
        };

        appRecovery.setRestartWant(want);
    })

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Pan-sensor Subsystem Changelog

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/a7471f6556d142149f58df8978683dc4