harmony(鸿蒙)AbilityDelegator

  • 2022-08-09
  • 浏览 (552)

AbilityDelegator

The AbilityDelegator module provides APIs for managing AbilityMonitor instances that are used to monitor the lifecycle state changes of a specified ability. You can use the APIs to add and remove AbilityMonitor instances, wait for an ability to reach the OnCreate lifecycle state, set the waiting time, obtain the lifecycle state of an ability, obtain the top ability of the current application, and start an ability.

NOTE

The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.

Usage

The ability delegator can be obtained by calling getAbilityDelegator in AbilityDelegatorRegistry.

import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'

var abilityDelegator;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();

AbilityDelegator

addAbilityMonitor9+

addAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback<void>): void

Adds an AbilityMonitor instance. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityMonitor Yes AbilityMonitor instance.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

var abilityDelegator;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    abilityName: "abilityname",
    onAbilityCreate: onAbilityCreateCallback
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.addAbilityMonitor(monitor, (err : any) => {
    console.info("addAbilityMonitor callback");
});

addAbilityMonitor9+

addAbilityMonitor(monitor: AbilityMonitor): Promise<void>

Adds an AbilityMonitor instance. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityMonitor Yes AbilityMonitor instance.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

var abilityDelegator;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    abilityName: "abilityname",
    onAbilityCreate: onAbilityCreateCallback
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.addAbilityMonitor(monitor).then(() => {
    console.info("addAbilityMonitor promise");
});

removeAbilityMonitor9+

removeAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback<void>): void

Removes an AbilityMonitor instance. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityMonitor Yes AbilityMonitor instance.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

var abilityDelegator;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    abilityName: "abilityname",
    onAbilityCreate: onAbilityCreateCallback
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.removeAbilityMonitor(monitor, (err : any) => {
    console.info("removeAbilityMonitor callback");
});

removeAbilityMonitor9+

removeAbilityMonitor(monitor: AbilityMonitor): Promise<void>

Removes an AbilityMonitor instance. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityMonitor Yes AbilityMonitor instance.

Return value

Type Description
Promise<void> Promise used to return the result.
  • Example
var abilityDelegator;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    abilityName: "abilityname",
    onAbilityCreate: onAbilityCreateCallback
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.removeAbilityMonitor(monitor).then(() => {
    console.info("removeAbilityMonitor promise");
});

waitAbilityMonitor9+

waitAbilityMonitor(monitor: AbilityMonitor, callback: AsyncCallback<Ability>): void

Waits for the Ability instance that matches the AbilityMonitor instance to reach the OnCreate lifecycle state and returns the Ability instance. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityMonitor Yes AbilityMonitor instance.
callback AsyncCallback<Ability> Yes Callback used to return the result.

Example

var abilityDelegator;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    abilityName: "abilityname",
    onAbilityCreate: onAbilityCreateCallback
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.waitAbilityMonitor(monitor, (err : any, data : any) => {
    console.info("waitAbilityMonitor callback");
});

waitAbilityMonitor9+

waitAbilityMonitor(monitor: AbilityMonitor, timeout: number, callback: AsyncCallback<Ability>): void

Waits a period of time for the Ability instance that matches the AbilityMonitor instance to reach the OnCreate lifecycle state and returns the Ability instance. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityMonitor Yes AbilityMonitor instance.
timeout number Yes Maximum waiting time, in milliseconds.
callback AsyncCallback<Ability> Yes Callback used to return the result.

Example

var abilityDelegator;
var timeout = 100;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    abilityName: "abilityname",
    onAbilityCreate: onAbilityCreateCallback
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.waitAbilityMonitor(monitor, timeout, (err : any, data : any) => {
    console.info("waitAbilityMonitor callback");
});

waitAbilityMonitor9+

waitAbilityMonitor(monitor: AbilityMonitor, timeout?: number): Promise<Ability>

Waits a period of time for the Ability instance that matches the AbilityMonitor instance to reach the OnCreate lifecycle state and returns the Ability instance. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityMonitor Yes AbilityMonitor instance.
timeout number No Maximum waiting time, in milliseconds.

Return value

Type Description
Promise<Ability> Promise used to return the Ability instance.

Example

var abilityDelegator;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    abilityName: "abilityname",
    onAbilityCreate: onAbilityCreateCallback
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.waitAbilityMonitor(monitor).then((data : any) => {
    console.info("waitAbilityMonitor promise");
});

getAppContext9+

getAppContext(): Context

Obtains the application context.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Return value

Type Description
Context Context of the application.

Example

var abilityDelegator;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var context = abilityDelegator.getAppContext();

getAbilityState9+

getAbilityState(ability: Ability): number

Obtains the lifecycle state of an ability.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
ability Ability Yes Target ability.

Return value

Type Description
number Lifecycle state of the ability. For details about the available enumerated values, see AbilityLifecycleState.

Example

var abilityDelegator;
var ability;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
    console.info("getCurrentTopAbility callback");
    ability = data;
    var state = abilityDelegator.getAbilityState(ability);
    console.info("getAbilityState" + state);
});

getCurrentTopAbility9+

getCurrentTopAbility(callback: AsyncCallback<Ability>): void

Obtains the top ability of this application. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
callback AsyncCallback<Ability> Yes Callback used to return the result.

Example

var abilityDelegator;
var ability;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
    console.info("getCurrentTopAbility callback");
    ability = data;
});

getCurrentTopAbility9+

getCurrentTopAbility(): Promise<Ability>

Obtains the top ability of this application. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Return value

Type Description
Promise<Ability> Promise used to return the top ability.

Example

var abilityDelegator;
var ability;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility().then((data : any) => {
    console.info("getCurrentTopAbility promise");
    ability = data;
});

startAbility9+

startAbility(want: Want, callback: AsyncCallback<void>): void

Starts an ability. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
want Want Yes Want parameter for starting the ability.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

var abilityDelegator;
var want = {
    bundleName: "bundleName",
    abilityName: "abilityName"
};

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.startAbility(want, (err : any, data : any) => {
    console.info("startAbility callback");
});

startAbility9+

startAbility(want: Want): Promise<void>

Starts an ability. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
want Want Yes Want parameter for starting the ability.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

var abilityDelegator;
var want = {
    bundleName: "bundleName",
    abilityName: "abilityName"
};

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.startAbility(want).then((data: any) => {
    console.info("startAbility promise");
});

doAbilityForeground9+

doAbilityForeground(ability: Ability, callback: AsyncCallback<boolean>): void

Schedules the lifecycle state of an ability to Foreground. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
ability Ability Yes Target ability.
callback AsyncCallback<boolean> Yes Callback used to return the result.
- true: The operation is successful.
- false: The operation failed.

Example

var abilityDelegator;
var ability;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
    console.info("getCurrentTopAbility callback");
    ability = data;
    abilityDelegator.doAbilityForeground(ability, (err : any, data : any) => {
        console.info("doAbilityForeground callback");
    });
});

doAbilityForeground9+

doAbilityForeground(ability: Ability): Promise<boolean>

Schedules the lifecycle state of an ability to Foreground. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
ability Ability Yes Target ability.

Return value

Type Description
Promise<boolean> Promise used to return the result.
- true: The operation is successful.
- false: The operation failed.

Example

var abilityDelegator;
var ability;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
    console.info("getCurrentTopAbility callback");
    ability = data;
    abilityDelegator.doAbilityForeground(ability).then((data : any) => {
        console.info("doAbilityForeground promise");
    });
});

doAbilityBackground9+

doAbilityBackground(ability: Ability, callback: AsyncCallback<boolean>): void

Schedules the lifecycle state of an ability to Background. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
ability Ability Yes Target ability.
callback AsyncCallback<boolean> Yes Callback used to return the result.
- true: The operation is successful.
- false: The operation failed.

Example

var abilityDelegator;
var ability;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
    console.info("getCurrentTopAbility callback");
    ability = data;
    abilityDelegator.doAbilityBackground(ability, (err : any, data : any) => {
        console.info("doAbilityBackground callback");
    });
});

doAbilityBackground9+

doAbilityBackground(ability: Ability): Promise<boolean>

Schedules the lifecycle state of an ability to Background. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
ability Ability Yes Target ability.

Return value

Type Description
Promise<boolean> Promise used to return the result.
- true: The operation is successful.
- false: The operation failed.

Example

var abilityDelegator;
var ability;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
    console.info("getCurrentTopAbility callback");
    ability = data;
    abilityDelegator.doAbilityBackground(ability).then((data : any) => {
        console.info("doAbilityBackground promise");
    });
});

printSync9+

printSync(msg: string): void

Prints log information to the unit test console.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
msg string Yes Log string.

Example

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.printSync(msg);

print

print(msg: string, callback: AsyncCallback<void>): void

Prints log information to the unit test console. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
msg string Yes Log string.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.print(msg, (err : any) => {
    console.info("print callback");
});

print

print(msg: string): Promise<void>

Prints log information to the unit test console. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
msg string Yes Log string.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.print(msg).then(() => {
    console.info("print promise");
});

executeShellCommand

executeShellCommand(cmd: string, callback: AsyncCallback<ShellCmdResult>): void

Executes a shell command. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
cmd string Yes Shell command string.
callback AsyncCallback<ShellCmdResult> Yes Callback used to return the result.

Example

var abilityDelegator;
var cmd = "cmd";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.executeShellCommand(cmd, (err : any, data : any) => {
    console.info("executeShellCommand callback");
});

executeShellCommand

executeShellCommand(cmd: string, timeoutSecs: number, callback: AsyncCallback<ShellCmdResult>): void

Executes a shell command with the timeout period specified. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
cmd string Yes Shell command string.
timeoutSecs number Yes Command timeout period, in seconds.
callback AsyncCallback<ShellCmdResult> Yes Callback used to return the result.

Example

var abilityDelegator;
var cmd = "cmd";
var timeout = 100;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.executeShellCommand(cmd, timeout, (err : any, data : any) => {
    console.info("executeShellCommand callback");
});

executeShellCommand

executeShellCommand(cmd: string, timeoutSecs?: number): Promise<ShellCmdResult>

Executes a shell command with the timeout period specified. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
cmd string Yes Shell command string.
timeoutSecs number No Command timeout period, in seconds.

Return value

Type Description
Promise<ShellCmdResult> Promise used to return a ShellCmdResult object.

Example

var abilityDelegator;
var cmd = "cmd";
var timeout = 100;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.executeShellCommand(cmd, timeout).then((data : any) => {
    console.info("executeShellCommand promise");
});

finishTest9+

finishTest(msg: string, code: number, callback: AsyncCallback<void>): void

Finishes the test and prints log information to the unit test console. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
msg string Yes Log string.
code number Yes Log code.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.finishTest(msg, 0, (err : any) => {
    console.info("finishTest callback");
});

finishTest9+

finishTest(msg: string, code: number): Promise<void>

Finishes the test and prints log information to the unit test console. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
msg string Yes Log string.
code number Yes Log code.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.finishTest(msg, 0).then(() => {
    console.info("finishTest promise");
});

addAbilityStageMonitor9+

addAbilityStageMonitor(monitor: AbilityStageMonitor, callback: AsyncCallback<void>): void;

Adds an AbilityStageMonitor instance to monitor the lifecycle state changes of an ability stage. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityStageMonitor Yes AbilityStageMonitor instance.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

var abilityDelegator;

var monitor = {
    moduleName: "moduleName",
    srcEntrance: "srcEntrance",
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.addAbilityStageMonitor(monitor, (err : any) => {
    console.info("addAbilityStageMonitor callback");
});

addAbilityStageMonitor9+

addAbilityStageMonitor(monitor: AbilityStageMonitor): Promise<void>;

Adds an AbilityStageMonitor instance to monitor the lifecycle state changes of an ability stage. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityStageMonitor Yes AbilityStageMonitor instance.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

var abilityDelegator;

var monitor = {
    moduleName: "moduleName",
    srcEntrance: "srcEntrance",
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.addAbilityStageMonitor(monitor).then(() => {
    console.info("addAbilityStageMonitor promise");
});

removeAbilityStageMonitor9+

removeAbilityStageMonitor(monitor: AbilityStageMonitor, callback: AsyncCallback<void>): void;

Removes an AbilityStageMonitor instance from the application memory. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityStageMonitor Yes AbilityStageMonitor instance.
callback AsyncCallback<void> Yes Callback used to return the result.

Example

var abilityDelegator;

var monitor = {
    moduleName: "moduleName",
    srcEntrance: "srcEntrance",
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.removeAbilityStageMonitor(monitor, (err : any) => {
    console.info("removeAbilityStageMonitor callback");
});

removeAbilityStageMonitor9+

removeAbilityStageMonitor(monitor: AbilityStageMonitor): Promise<void>;

Removes an AbilityStageMonitor object from the application memory. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityStageMonitor Yes AbilityStageMonitor instance.

Return value

Type Description
Promise<void> Promise used to return the result.

Example

var abilityDelegator;

var monitor = {
    moduleName: "moduleName",
    srcEntrance: "srcEntrance",
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.removeAbilityStageMonitor(monitor).then(() => {
    console.info("removeAbilityStageMonitor promise");
});

waitAbilityStageMonitor9+

waitAbilityStageMonitor(monitor: AbilityStageMonitor, callback: AsyncCallback<AbilityStage>): void;

Waits for an AbilityStage instance that matches the conditions set in an AbilityStageMonitor instance and returns the AbilityStage instance. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityStageMonitor Yes AbilityStageMonitor instance.
callback AsyncCallback<AbilityStage> Yes Callback used to return the result. If the operation is successful, an AbilityStage instance is returned. Otherwise, no value is returned.

Example

var abilityDelegator;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    moduleName: "moduleName",
    srcEntrance: "srcEntrance",
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.waitAbilityStageMonitor(monitor, (err : any, data : any) => {
    console.info("waitAbilityStageMonitor callback");
});

waitAbilityStageMonitor9+

waitAbilityStageMonitor(monitor: AbilityStageMonitor, timeout?: number): Promise<AbilityStage>;

Waits for an AbilityStage instance that matches the conditions set in an AbilityStageMonitor instance and returns the AbilityStage instance. This API uses a promise to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityStageMonitor Yes AbilityStageMonitor instance.
timeout number No Maximum waiting time, in milliseconds.

Return value

Type Description
Promise<AbilityStage> Promise used to return the result. If the operation is successful, an AbilityStage instance is returned. Otherwise, no value is returned.

Example

var abilityDelegator;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    moduleName: "moduleName",
    srcEntrance: "srcEntrance",
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.waitAbilityStageMonitor(monitor).then((data : any) => {
    console.info("waitAbilityStageMonitor promise");
});

waitAbilityStageMonitor9+

waitAbilityStageMonitor(monitor: AbilityStageMonitor, timeout: number, callback: AsyncCallback<AbilityStage>): void;

Waits a period of time for an AbilityStage instance that matches the conditions set in an AbilityStageMonitor instance and returns the AbilityStage instance. This API uses an asynchronous callback to return the result.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Parameters

Name Type Mandatory Description
monitor AbilityStageMonitor Yes AbilityStageMonitor instance.
timeout number No Maximum waiting time, in milliseconds.
callback AsyncCallback<AbilityStage> Yes Callback used to return the result. If the operation is successful, an AbilityStage instance is returned. Otherwise, no value is returned.

Example

var abilityDelegator;
var timeout = 100;

function onAbilityCreateCallback(data) {
    console.info("onAbilityCreateCallback");
}

var monitor = {
    moduleName: "moduleName",
    srcEntrance: "srcEntrance",
}

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.waitAbilityStageMonitor(monitor, timeout, (err : any, data : any) => {
    console.info("waitAbilityStageMonitor callback");
});

AbilityStageMonitor

Provides conditions for matching AbilityStage instances. The most recently matched AbilityStage instance is saved in an AbilityStageMonitor instance.

System capability: SystemCapability.Ability.AbilityRuntime.Core

Name Type Readable Writable Description
moduleName9+ string Yes Yes Module name of the AbilityStage instance.
srcEntrance9+ string Yes Yes Source path of the AbilityStage instance.

你可能感兴趣的鸿蒙文章

harmony(鸿蒙)APIs

harmony(鸿蒙)API Reference Document Description

harmony(鸿蒙)BundleStatusCallback

harmony(鸿蒙)innerBundleManager(deprecated)

harmony(鸿蒙)distributedBundle

harmony(鸿蒙)Bundle

harmony(鸿蒙)Context

harmony(鸿蒙)DataUriUtils

harmony(鸿蒙)EnterpriseAdminExtensionAbility

harmony(鸿蒙)Work Scheduler Callbacks

0  赞