Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
d7ae8dcc
D
Docs
项目概览
OpenHarmony
/
Docs
12 个月 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d7ae8dcc
编写于
12月 27, 2022
作者:
zyjhandsome
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化《@ohos.app.ability.appManager (appManager)》章节部分内容,修复'on'示例代码问题
Signed-off-by:
zyjhandsome
<
zyjhandsome@126.com
>
上级
d7a488ad
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
55 addition
and
55 deletion
+55
-55
zh-cn/application-dev/reference/apis/js-apis-app-ability-appManager.md
...tion-dev/reference/apis/js-apis-app-ability-appManager.md
+55
-55
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-app-ability-appManager.md
浏览文件 @
d7ae8dcc
...
...
@@ -30,7 +30,7 @@ static isRunningInStabilityTest(callback: AsyncCallback<boolean>): void
```
ts
appManager
.
isRunningInStabilityTest
((
err
,
flag
)
=>
{
if
(
err
.
code
!=
0
)
{
if
(
err
.
code
!=
=
0
)
{
conseole
.
log
(
"
isRunningInStabilityTest faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The result of isRunningInStabilityTest is:
"
+
JSON
.
stringify
(
flag
));
...
...
@@ -106,7 +106,7 @@ isRamConstrainedDevice(callback: AsyncCallback\<boolean>): void;
```
ts
appManager
.
isRamConstrainedDevice
((
err
,
data
)
=>
{
if
(
err
.
code
!=
0
)
{
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
isRamConstrainedDevice faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The result of isRamConstrainedDevice is:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -156,7 +156,7 @@ getAppMemorySize(callback: AsyncCallback\<number>): void;
```
ts
appManager
.
getAppMemorySize
((
err
,
data
)
=>
{
if
(
err
.
code
!=
0
)
{
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
getAppMemorySize faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The size of app memory is:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -214,7 +214,7 @@ getProcessRunningInformation(callback: AsyncCallback\<Array\<ProcessRunningInfor
```
ts
appManager
.
getProcessRunningInformation
((
err
,
data
)
=>
{
if
(
err
.
code
!=
0
)
{
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
getProcessRunningInformation faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
The process running information is:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -250,28 +250,28 @@ on(type: "applicationState", observer: ApplicationStateObserver): number;
**示例:**
```
js
var
applicationStateObserver
=
{
let
applicationStateObserver
=
{
onForegroundApplicationChanged
(
appStateData
)
{
console
.
log
(
'
------------ onForegroundApplicationChanged -----------
'
+
JSON
.
stringify
(
appStateData
)
);
console
.
log
(
`[appManager] onForegroundApplicationChanged:
${
JSON
.
stringify
(
appStateData
)}
`
);
},
onAbilityStateChanged
(
abilityStateData
)
{
console
.
log
(
'
------------ onAbilityStateChanged -----------
'
+
JSON
.
stringify
(
abilityStateData
)
);
console
.
log
(
`[appManager] onAbilityStateChanged:
${
JSON
.
stringify
(
abilityStateData
)}
`
);
},
onProcessCreated
(
processData
)
{
console
.
log
(
'
------------ onProcessCreated -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessCreated:
${
JSON
.
stringify
(
processData
)}
`
);
},
onProcessDied
(
processData
)
{
console
.
log
(
'
------------ onProcessDied -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessDied:
${
JSON
.
stringify
(
processData
)}
`
);
},
onProcessStateChanged
(
processData
)
{
console
.
log
(
'
------------ onProcessStateChanged -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessStateChanged:
${
JSON
.
stringify
(
processData
)}
`
);
}
}
try
{
const
observerCode
=
appManager
.
on
(
applicationStateObserver
);
console
.
log
(
'
-------- observerCode: ---------
'
+
observerCode
);
const
observerCode
=
appManager
.
on
(
'
applicationState
'
,
applicationStateObserver
);
console
.
log
(
`[appManager] observerCode:
${
observerCode
}
`
);
}
catch
(
paramError
)
{
console
.
log
(
'
error:
'
+
paramError
.
code
+
'
,
'
+
paramError
.
message
);
console
.
log
(
`[appManager] error:
${
paramError
.
code
}
,
${
paramError
.
message
}
`
);
}
```
...
...
@@ -293,7 +293,7 @@ on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList:
| -------- | -------- | -------- | -------- |
| type | string | 是 | 调用接口类型,固定填"applicationState"字符串。 |
| observer |
[
ApplicationStateObserver
](
./js-apis-inner-application-applicationStateObserver.md
)
| 是 | 应用状态观测器,用于观测应用的生命周期变化。 |
| bundleNameList |
Array
<string>
| 是 | 表示需要注册监听的bundleName数组。最大值128。 |
| bundleNameList |
`Array<string>`
| 是 | 表示需要注册监听的bundleName数组。最大值128。 |
**返回值:**
...
...
@@ -304,31 +304,31 @@ on(type: "applicationState", observer: ApplicationStateObserver, bundleNameList:
**示例:**
```
js
var
applicationStateObserver
=
{
let
applicationStateObserver
=
{
onForegroundApplicationChanged
(
appStateData
)
{
console
.
log
(
'
------------ onForegroundApplicationChanged -----------
'
+
JSON
.
stringify
(
appStateData
)
);
console
.
log
(
`[appManager] onForegroundApplicationChanged:
${
JSON
.
stringify
(
appStateData
)}
`
);
},
onAbilityStateChanged
(
abilityStateData
)
{
console
.
log
(
'
------------ onAbilityStateChanged -----------
'
+
JSON
.
stringify
(
abilityStateData
)
);
console
.
log
(
`[appManager] onAbilityStateChanged:
${
JSON
.
stringify
(
abilityStateData
)}
`
);
},
onProcessCreated
(
processData
)
{
console
.
log
(
'
------------ onProcessCreated -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessCreated:
${
JSON
.
stringify
(
processData
)}
`
);
},
onProcessDied
(
processData
)
{
console
.
log
(
'
------------ onProcessDied -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessDied:
${
JSON
.
stringify
(
processData
)}
`
);
},
onProcessStateChanged
(
processData
)
{
console
.
log
(
'
------------ onProcessStateChanged -----------
'
+
JSON
.
stringify
(
processData
)
);
console
.
log
(
`[appManager] onProcessStateChanged:
${
JSON
.
stringify
(
processData
)}
`
);
}
}
var
bundleNameList
=
[
'
bundleName1
'
,
'
bundleName2
'
];
let
bundleNameList
=
[
'
bundleName1
'
,
'
bundleName2
'
];
try
{
const
observerCode
=
appManager
.
on
(
"
applicationState
"
,
applicationStateObserver
,
bundleNameList
);
console
.
log
(
'
-------- observerCode: ---------
'
,
observerCode
);
console
.
log
(
`[appManager] observerCode:
${
observerCode
}
`
);
}
catch
(
paramError
)
{
console
.
log
(
'
error:
'
+
paramError
.
code
+
'
,
'
+
paramError
.
message
);
console
.
log
(
`[appManager] error:
${
paramError
.
code
}
,
${
paramError
.
message
}
`
);
}
```
```
## appManager.off
...
...
@@ -353,10 +353,10 @@ off(type: "applicationState", observerId: number, callback: AsyncCallback\<void
**示例:**
```
ts
var
observerId = 100;
let
observerId
=
100
;
function
unregisterApplicationStateObserverCallback
(
err
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
unregisterApplicationStateObserverCallback faile, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
unregisterApplicationStateObserverCallback success.
"
);
...
...
@@ -397,7 +397,7 @@ off(type: "applicationState", observerId: number): Promise\<void>;
**示例:**
```
ts
var
observerId = 100;
let
observerId
=
100
;
try
{
appManager
.
off
(
observerId
).
then
((
data
)
=>
{
...
...
@@ -432,7 +432,7 @@ getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
```
ts
function
getForegroundApplicationsCallback
(
err
,
data
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
getForegroundApplicationsCallback fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
getForegroundApplicationsCallback success, data:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -467,7 +467,7 @@ getForegroundApplications(callback: AsyncCallback\<Array\<AppStateData>>): void;
```
ts
function
getForegroundApplicationsCallback
(
err
,
data
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
getForegroundApplicationsCallback fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
getForegroundApplicationsCallback success, data:
"
+
JSON
.
stringify
(
data
));
...
...
@@ -530,8 +530,8 @@ killProcessWithAccount(bundleName: string, accountId: number): Promise\<void\>
**示例:**
```
ts
var
bundleName = 'bundleName';
var
accountId = 0;
let
bundleName
=
'
bundleName
'
;
let
accountId
=
0
;
try
{
appManager
.
killProcessWithAccount
(
bundleName
,
accountId
).
then
(()
=>
{
console
.
log
(
"
killProcessWithAccount success
"
);
...
...
@@ -570,7 +570,7 @@ killProcessWithAccount(bundleName: string, accountId: number, callback: AsyncCal
var
bundleName
=
'
bundleName
'
;
var
accountId
=
0
;
function
killProcessWithAccountCallback
(
err
,
data
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
killProcessWithAccountCallback fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
killProcessWithAccountCallback success.
"
);
...
...
@@ -603,7 +603,7 @@ killProcessesByBundleName(bundleName: string, callback: AsyncCallback\<void>);
```
ts
var
bundleName
=
'
bundleName
'
;
function
killProcessesByBundleNameCallback
(
err
,
data
)
{
if (err.code != 0) {
if
(
err
.
code
!=
=
0
)
{
console
.
log
(
"
killProcessesByBundleNameCallback fail, err:
"
+
JSON
.
stringify
(
err
));
}
else
{
console
.
log
(
"
killProcessesByBundleNameCallback success.
"
);
...
...
@@ -643,7 +643,7 @@ killProcessesByBundleName(bundleName: string): Promise\<void>;
**示例:**
```
ts
var
bundleName = 'bundleName';
let
bundleName
=
'
bundleName
'
;
try
{
appManager
.
killProcessesByBundleName
(
bundleName
).
then
((
data
)
=>
{
console
.
log
(
"
killProcessesByBundleName success.
"
);
...
...
@@ -677,7 +677,7 @@ clearUpApplicationData(bundleName: string, callback: AsyncCallback\<void>);
**示例:**
```
ts
var
bundleName = 'bundleName';
let
bundleName
=
'
bundleName
'
;
function
clearUpApplicationDataCallback
(
err
,
data
)
{
if
(
err
)
{
console
.
log
(
"
clearUpApplicationDataCallback fail, err:
"
+
JSON
.
stringify
(
err
));
...
...
@@ -719,7 +719,7 @@ clearUpApplicationData(bundleName: string): Promise\<void>;
**示例:**
```
ts
var
bundleName = 'bundleName';
let
bundleName
=
'
bundleName
'
;
try
{
appManager
.
clearUpApplicationData
(
bundleName
).
then
((
data
)
=>
{
console
.
log
(
"
clearUpApplicationData success.
"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录