harmony 鸿蒙@ohos.app.ability.abilityDelegatorRegistry (AbilityDelegatorRegistry)

  • 2022-12-22
  • 浏览 (538)

@ohos.app.ability.abilityDelegatorRegistry (AbilityDelegatorRegistry)

AbilityDelegatorRegistry, a module of the Automatic Test Framework, is used to obtain AbilityDelegator and AbilityDelegatorArgs objects. AbilityDelegator provides APIs for creating AbilityMonitor objects, which can be used to listen for ability lifecycle changes. AbilityDelegatorArgs provides APIs for obtaining test parameters.

NOTE

The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version. The APIs provided by this module can be used only in the test framework.

Modules to Import

import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';

AbilityLifecycleState

Enumerates the ability lifecycle states. It can be used in getAbilityState(ability) of AbilityDelegator to return different ability lifecycle states.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Name Value Description
UNINITIALIZED 0 The ability is in an invalid state.
CREATE 1 The ability is created.
FOREGROUND 2 The ability is running in the foreground.
BACKGROUND 3 The ability is running in the background.
DESTROY 4 The ability is destroyed.

AbilityDelegatorRegistry.getAbilityDelegator

getAbilityDelegator(): AbilityDelegator

Obtains an AbilityDelegator object.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Return value

Type Description
AbilityDelegator AbilityDelegator object, which can be used to schedule the functionalities of the test framework.

Example

import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';
import Want from '@ohos.app.ability.Want';

let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();

let want: Want = {
    bundleName: 'com.example.myapplication',
    abilityName: 'EntryAbility'
};
abilityDelegator.startAbility(want, (err) => {
    if (err) {
        console.error(`Failed start ability, error: ${JSON.stringify(err)}`);
    } else {
        console.log('Success start ability.');
    }
});

AbilityDelegatorRegistry.getArguments

getArguments(): AbilityDelegatorArgs

Obtains an AbilityDelegatorArgs object.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Return value

Type Description
AbilityDelegatorArgs AbilityDelegatorArgs object, which can be used to obtain test parameters.

Example

import AbilityDelegatorRegistry from '@ohos.app.ability.abilityDelegatorRegistry';

let args = AbilityDelegatorRegistry.getArguments();
console.info(`getArguments bundleName: ${args.bundleName}`);
console.info(`getArguments parameters: ${JSON.stringify(args.parameters)}`);
console.info(`getArguments testCaseNames: ${args.testCaseNames}`);
console.info(`getArguments testRunnerClassName: ${args.testRunnerClassName}`);

你可能感兴趣的鸿蒙文章

harmony 鸿蒙APIs

harmony 鸿蒙System Common Events (To Be Deprecated Soon)

harmony 鸿蒙System Common Events

harmony 鸿蒙API Reference Document Description

harmony 鸿蒙Enterprise Device Management Overview (for System Applications Only)

harmony 鸿蒙BundleStatusCallback

harmony 鸿蒙@ohos.bundle.innerBundleManager (innerBundleManager)

harmony 鸿蒙@ohos.distributedBundle (Distributed Bundle Management)

harmony 鸿蒙@ohos.bundle (Bundle)

harmony 鸿蒙@ohos.enterprise.EnterpriseAdminExtensionAbility (EnterpriseAdminExtensionAbility)

0  赞