AbilityDelegator


AbilityDelegator

AbilityDelegator提供添加用于监视指定ability的生命周期状态更改的AbilityMonitor对象的能力,包括对AbilityMonitor实例的添加、删除、等待ability到达OnCreate生命周期、设置等待时间等、获取指定ability的生命周期状态、获取当前应用顶部ability、启动指定ability等。

说明:

本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

使用说明

通过AbilityDelegatorRegistry中getAbilityDelegator方法获取。

import AbilityDelegatorRegistry from '@ohos.application.abilityDelegatorRegistry'

let abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
1
2
3

AbilityDelegator

addAbilityMonitor9+

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

添加AbilityMonitor实例(callback形式)

**系统能力:**SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityMonitor AbilityMonitor实例
callback AsyncCallback<void> 表示指定的回调方法

示例:

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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

addAbilityMonitor9+

addAbilityMonitor(monitor: AbilityMonitor): Promise<void>;

添加AbilityMonitor实例(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityMonitor AbilityMonitor实例

返回值:

类型 说明
Promise<void> 以Promise形式返回。

示例:

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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

removeAbilityMonitor9+

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

删除已经添加的AbilityMonitor实例(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityMonitor AbilityMonitor实例
callback AsyncCallback<void> 表示指定的回调方法

示例:

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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

removeAbilityMonitor9+

removeAbilityMonitor(monitor: AbilityMonitor): Promise<void>;

删除已经添加的AbilityMonitor实例(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityMonitor AbilityMonitor实例

返回值:

类型 说明
Promise<void> 以Promise形式返回。
  • 示例
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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

waitAbilityMonitor9+

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

等待与AbilityMonitor实例匹配的ability到达OnCreate生命周期,并返回ability实例(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityMonitor AbilityMonitor实例
callback AsyncCallback<UIAbility> 表示指定的回调方法

示例:

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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

waitAbilityMonitor9+

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

设置等待时间,等待与AbilityMonitor实例匹配的ability到达OnCreate生命周期,并返回ability实例(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityMonitor AbilityMonitor实例
timeout number 最大等待时间,单位毫秒(ms)
callback AsyncCallback<UIAbility> 表示指定的回调方法

示例:

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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

waitAbilityMonitor9+

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

设置等待时间,等待与AbilityMonitor实例匹配的ability到达OnCreate生命周期,并返回ability实例(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityMonitor AbilityMonitor实例
timeout number 最大等待时间,单位毫秒(ms)

返回值:

类型 说明
Promise<UIAbility> 以Promise形式返回Ability。

示例:

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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

getAppContext9+

getAppContext(): Context;

获取应用Context

系统能力: SystemCapability.Ability.AbilityRuntime.Core

返回值:

类型 说明
Context 应用Context

示例:

var abilityDelegator;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
var context = abilityDelegator.getAppContext();
1
2
3
4

getAbilityState9+

getAbilityState(ability: UIAbility): number;

获取指定ability的生命周期状态

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
ability UIAbility 指定Ability对象

返回值:

类型 说明
number 指定ability的生命周期状态。状态枚举值使用AbilityLifecycleState

示例:

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);
});
1
2
3
4
5
6
7
8
9
10

getCurrentTopAbility9+

getCurrentTopAbility(callback: AsyncCallback<UIAbility>): void;

获取当前应用顶部ability(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<UIAbility> 表示指定的回调方法

示例:

var abilityDelegator;
var ability;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility((err : any, data : any) => {
    console.info("getCurrentTopAbility callback");
    ability = data;
});
1
2
3
4
5
6
7
8

getCurrentTopAbility9+

getCurrentTopAbility(): Promise<UIAbility>;

获取当前应用顶部ability(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

返回值:

类型 说明
Promise<UIAbility> 以Promise形式返回当前应用顶部ability。

示例:

var abilityDelegator;
var ability;

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.getCurrentTopAbility().then((data : any) => {
    console.info("getCurrentTopAbility promise");
    ability = data;
});
1
2
3
4
5
6
7
8

startAbility9+

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

启动指定ability(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
want Want 启动Ability参数
callback AsyncCallback<void> 表示指定的回调方法

示例:

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

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.startAbility(want, (err : any, data : any) => {
    console.info("startAbility callback");
});
1
2
3
4
5
6
7
8
9
10

startAbility9+

startAbility(want: Want): Promise<void>;

启动指定ability(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
want Want 启动Ability参数

返回值:

类型 说明
Promise<void> 以Promise形式返回。

示例:

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

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.startAbility(want).then((data: any) => {
    console.info("startAbility promise");
});
1
2
3
4
5
6
7
8
9
10

doAbilityForeground9+

doAbilityForeground(ability: UIAbility, callback: AsyncCallback<void>): void;

调度指定ability生命周期状态到Foreground状态(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
ability UIAbility 指定Ability对象
callback AsyncCallback<void> 表示指定的回调方法
- true:成功
- false:失败

示例:

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");
    });
});
1
2
3
4
5
6
7
8
9
10
11

doAbilityForeground9+

doAbilityForeground(ability: UIAbility): Promise<void>;

调度指定ability生命周期状态到Foreground状态(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
ability UIAbility 指定Ability对象

返回值:

类型 说明
Promise<boolean> 以Promise形式返回执行结果。
- true:成功
- false:失败

示例:

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");
    });
});
1
2
3
4
5
6
7
8
9
10
11

doAbilityBackground9+

doAbilityBackground(ability: UIAbility, callback: AsyncCallback<void>): void;

调度指定ability生命周期状态到Background状态(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
ability UIAbility 指定Ability对象
callback AsyncCallback<void> 表示指定的回调方法
- true:成功
- false:失败

示例:

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");
    });
});
1
2
3
4
5
6
7
8
9
10
11

doAbilityBackground9+

doAbilityBackground(ability: UIAbility): Promise<void>;

调度指定ability生命周期状态到Background状态(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
ability UIAbility 指定Ability对象

返回值:

类型 说明
Promise<boolean> 以Promise形式返回执行结果。
- true:成功
- false:失败

示例:

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");
    });
});
1
2
3
4
5
6
7
8
9
10
11

printSync9+

printSync(msg: string): void;

打印日志信息到单元测试终端控制台

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
msg string 日志字符串

示例:

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.printSync(msg);
1
2
3
4
5

print

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

打印日志信息到单元测试终端控制台(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
msg string 日志字符串
callback AsyncCallback<void> 表示指定的回调方法

示例:

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.print(msg, (err : any) => {
    console.info("print callback");
});
1
2
3
4
5
6
7

print(msg: string): Promise<void>;

打印日志信息到单元测试终端控制台(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
msg string 日志字符串

返回值:

类型 说明
Promise<void> 以Promise形式返回。

示例:

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.print(msg).then(() => {
    console.info("print promise");
});
1
2
3
4
5
6
7

executeShellCommand

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

执行指定的shell命令(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
cmd string shell命令字符串
callback AsyncCallback<ShellCmdResult> 表示指定的回调方法

示例:

var abilityDelegator;
var cmd = "cmd";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.executeShellCommand(cmd, (err : any, data : any) => {
    console.info("executeShellCommand callback");
});
1
2
3
4
5
6
7

executeShellCommand

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

指定超时时间,并执行指定的shell命令(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
cmd string shell命令字符串
timeoutSecs number 设定命令超时时间,单位秒(s)
callback AsyncCallback<ShellCmdResult> 表示指定的回调方法

示例:

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

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.executeShellCommand(cmd, timeout, (err : any, data : any) => {
    console.info("executeShellCommand callback");
});
1
2
3
4
5
6
7
8

executeShellCommand

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

指定超时时间,并执行指定的shell命令(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
cmd string shell命令字符串
timeoutSecs number 设定命令超时时间,单位秒(s)

返回值:

类型 说明
Promise<ShellCmdResult> 以Promise形式返回Shell命令执行结果ShellCmdResult对象。

示例:

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

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.executeShellCommand(cmd, timeout).then((data : any) => {
    console.info("executeShellCommand promise");
});
1
2
3
4
5
6
7
8

finishTest9+

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

结束测试并打印日志信息到单元测试终端控制台(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
msg string 日志字符串
code number 日志码
callback AsyncCallback<void> 表示指定的回调方法

示例:

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.finishTest(msg, 0, (err : any) => {
    console.info("finishTest callback");
});
1
2
3
4
5
6
7

finishTest9+

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

结束测试并打印日志信息到单元测试终端控制台(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
msg string 日志字符串
code number 日志码

返回值:

类型 说明
Promise<void> 以Promise形式返回。

示例:

var abilityDelegator;
var msg = "msg";

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.finishTest(msg, 0).then(() => {
    console.info("finishTest promise");
});
1
2
3
4
5
6
7

addAbilityStageMonitor9+

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

添加一个AbilityStageMonitor对象,用于监视指定abilityStage的生命周期状态更改。(callback形式)

**系统能力:**SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityStageMonitor AbilityStageMonitor 实例
callback AsyncCallback<void> 表示指定的回调方法

示例:

var abilityDelegator;

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

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.addAbilityStageMonitor(monitor, (err : any) => {
    console.info("addAbilityStageMonitor callback");
});
1
2
3
4
5
6
7
8
9
10
11

addAbilityStageMonitor9+

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

添加一个AbilityStageMonitor对象,用于监视指定abilityStage的生命周期状态更改。(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityStageMonitor AbilityStageMonitor 实例

返回值:

类型 说明
Promise<void> 以Promise形式返回。

示例:

var abilityDelegator;

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

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.addAbilityStageMonitor(monitor).then(() => {
    console.info("addAbilityStageMonitor promise");
});
1
2
3
4
5
6
7
8
9
10
11

removeAbilityStageMonitor9+

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

从应用程序内存中删除指定的AbilityStageMonitor对象。(callback形式)

**系统能力:**SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityStageMonitor AbilityStageMonitor 实例
callback AsyncCallback<void> 表示指定的回调方法

示例:

var abilityDelegator;

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

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.removeAbilityStageMonitor(monitor, (err : any) => {
    console.info("removeAbilityStageMonitor callback");
});
1
2
3
4
5
6
7
8
9
10
11

removeAbilityStageMonitor9+

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

从应用程序内存中删除指定的AbilityStageMonitor对象。(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityStageMonitor AbilityStageMonitor 实例

返回值:

类型 说明
Promise<void> 以Promise形式返回。

示例:

var abilityDelegator;

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

abilityDelegator = AbilityDelegatorRegistry.getAbilityDelegator();
abilityDelegator.removeAbilityStageMonitor(monitor).then(() => {
    console.info("removeAbilityStageMonitor promise");
});
1
2
3
4
5
6
7
8
9
10
11

waitAbilityStageMonitor9+

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

等待并返回与给定AbilityStageMonitor中设置的条件匹配的AbilityStage对象。(callback形式)

**系统能力:**SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityStageMonitor AbilityStageMonitor 实例
callback AsyncCallback<AbilityStage> 成功返回AbilityStage对象,失败返回空。

示例:

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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

waitAbilityStageMonitor9+

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

等待并返回与给定AbilityStageMonitor中设置的条件匹配的AbilityStage对象。(promise形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityStageMonitor AbilityStageMonitor 实例
timeout number 超时最大等待时间,以毫秒为单位。

返回值:

类型 说明
Promise<AbilityStage> 成功返回AbilityStage对象,失败返回空。

示例:

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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

waitAbilityStageMonitor9+

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

等待并返回与给定AbilityStageMonitor中设置的条件匹配的AbilityStage对象。(callback形式)

系统能力: SystemCapability.Ability.AbilityRuntime.Core

参数:

参数名 类型 必填 说明
monitor AbilityStageMonitor AbilityStageMonitor 实例
timeout number 超时最大等待时间,以毫秒为单位。
callback AsyncCallback<AbilityStage> 成功返回AbilityStage对象,失败返回空。

示例:

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");
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16